Some assistance needed to improve HTTP call efficiency - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Some assistance needed to improve HTTP call efficiency (/showthread.php?tid=3187) |
Some assistance needed to improve HTTP call efficiency - Paddyb - 21.02.2021 Hi, I am running some scripts in my LM (a Schneider branded one for the CBUS protocol), and am using it to control a number of Sonoff relays via HTTP. My command to each device works perfect, I have an event script on each Group address I want to control a given Sonoff. Any time I activate my Cbus Group, the Sonoff follows it, as needed. My Sonoff’s also have local switches connected to their GPIO pins, and if a user presses one of the physical buttons on the Sonoff, the Group addresses ‘Status’ is then out of sync. So, I then created a resident script to run every 2 seconds to poll all the Sonoffs , retrieve their current status, and then update the Group address status if needed, putting things back in sync. I have about 10 Sonoffs, and I poll each one in a For loop, so it’s not the quickest… Also, unfortunately, when I fix the Group address Status/State with my resident script, it triggers another event script on that GA, which is not really necessary and is just consuming resources… I will post an abbreviation of my code here, but would love to get some advice on a more streamlined way to do the feedback part, without consuming too much CPU etc. Also, my resident script runs two-second intervals, but I could extend this out to 10 or 15 if needed. But still, would like to keep it as snappy as possible... Event Script Code: -- Enter IP Address of Tasmota Device Resident Script Code: -- Enter IP Address of Tasmota Device Would appreciate any suggestions on how to make this process more efficient/quicker. It works ok most of the time, but sometimes the scripts seem to step on each other, or the feedback is still out of sync. Particularly if there is a lot of persistent and quick pressing of the buttons (kids!). - Thanks. RE: Some assistance needed to improve HTTP call efficiency - admin - 22.02.2021 Have you considered using MQTT (https://tasmota.github.io/docs/MQTT/) for this? It looks like you can configure status updates to be published to MQTT automatically so polling is not needed. You can also check event.sender value in event scripts. It will tell you who triggered the event. Code: -- do nothing if triggered by a resident script RE: Some assistance needed to improve HTTP call efficiency - Paddyb - 22.02.2021 Thanks, Admin. I knew about the MQTT possibilities but was trying to avoid it if possible. I didn't want to set up another server to run MQTT for the sake of some feedback on my visualizations. I can't use any of the new LM firmware either (which has MQTT on board), as my device is a SHAC from Schneider, not a standard-issue LM. Anyways, following your tip, I eliminated a lot of bogus events and have reached an acceptable solution and level of performance. Checking for an 'sr' event didn't actually work for me, but after a bit of logging and debugging, I found the correct events for my device that I needed to act on, or ignore, as needed.. I put this at the start of each individual Event script, and now it is no longer re-triggered by my resident script.. Code: log ("Event Sender : ", event.sender) -- Inspect the sender - Returns 'cb' if a real event from cbus bus or 'cl' if it came from my resident script Thank you! RE: Some assistance needed to improve HTTP call efficiency - pspeirs - 11.10.2021 Just as a matter of information, the SHAC does support MQTT on board, just need to include the library. Cheers, Paul RE: Some assistance needed to improve HTTP call efficiency - myg - 13.10.2021 Another (might be much better) option is to flash Tasmota KNX and then have direct relay mapping via KNX/IP RE: Some assistance needed to improve HTTP call efficiency - Daniel - 13.10.2021 SHAC doesn't have KNX IP RE: Some assistance needed to improve HTTP call efficiency - myg - 13.10.2021 Damn, then it's time to buy separate gateway if system have need in wifi relays with seamless integration |