I am configuring Home Assistant to control other systems with RESTful calls to other systems. This setup of Home Assistant is newly installed on a Raspberry Pi 4 with AppDaemon 4 and Mosquitto broker also installed. AppDaemon is not enabled at this time. The IP address of the system is 192.168.1.60 with this entry in the configuration file:
The system at 192.168.1.27 is a Raspberry Pi 3 with a simple Python Flask server that responds to HTTP GETs on three different route, one of those being “/leds”.
The Pi 3 log shows that it is receiving GETs from the Pi 4 Home Assistant instance every 30 seconds:
The reference to a switch was removed from the dashboard and the system restarted, but nothing changed. There are no scripts, automations or any other elements that could be generating the calls.
I have wracked my brain and done innumerable searches on Google for any clues as to why this is happening, but nothing turned up until now. Upon reflection, I did another search that included “30 seconds” and came across the notion of “scan interval” in the description of “Entity integration” here.
With this, I am guessing that I need to pass a parameter within the URL, but any suggestions would be appreciated!
restful switches are IoT polling devices. Thus, they poll at the default interval of 30 seconds unless you specify a different rate.
The state usually changes instantly if you use HA because the switch itself will assume the command worked and change its state immediately. However, it will fix itself in the next polling interval if the command didn’t actually work.
However, if you change the switch state via any other method, HA won’t know about the change for up to scan_interval seconds (default 30).
Thanks so much for your response! The page you referenced was the first indication I had found as to what was going on. I only found it when I determined that the calls were happening every 30 seconds and included that fact in my searches.
What I am pursuing now is how to reference a URL and pass a parameter so that something happens on the device ONLY when needed. I am guessing that changes to the Flask server will make that possible. What’s not clear to me so far, however, is how to reference the device in my configuration.yaml and then reference the switch properly elsewhere (script or button on the dashboard) when I want to effect a change in its state.
When you create the restful switch, you will have a normal switch entity alive in your system. You can reference it with ‘switch.name’ if you define the name in the config. Otherwise, it will get some default name.
If you don’t want a polling device, create a restful command then a template switch to call the command (if you still want a switch).
By default, a GET command shouldn’t change the state of the switch. I would assume a POST command would, but it 100% depends on the implementation. If the GET is changing the state, do the restful_command instead so it doesn’t poll for state updates.
Perfect! That confirms the direction that I was thinking about pursuing!
It seems that I need to have the server differentiate between a GET and a POST. Doing that, it will then need to ignore the former and react to the latter as it does now every time upon receiving the GET.