I’m trying to run a script on the ESP from HASSIO. There’s hopefully a simple way of doing this as I can’t get it to work.
My idea was to create a (template) switch visible from HASSIO that when I turn it on, it will run the script in ESP. I’ve done that but it won’t run the script.
The script runs fine as I can trigger it from a remote control (IR)
I guess you have to use turn_on_action: instead of on_turn_on:
As is documented, the former means what will happen when some thing (like HA) tries to turn on the switch, and the later is an action that will be executed if the switch turns on.
Zombie thread, but having found this whilst trying to do the same, I thought you could have used template instead of faking a gpio, with your last sketch as follows:
Then I rolled one of my own, and found template didn’t seem to process any of the actions correctly, or call the logger outputs I was adding. So I followed your approach and faked a GPIO, and now it works.
Strange…
edit: realised proposal didn’t work. Rolled back on approach entirely and now agree with you )
Lol. Me either. The tinkerer in me says understanding why it works is just as important as whether it works. The pragmatist says, “it works. Move along…”
This may no longer be important, but I have a template switch with a similar-ish purpose. To get it to work i had to use the optimistic identifier in the switch yaml.
Using the optimistic option meant that when my switch was ‘flicked’ in home assistant it would force the switch to ‘flick’ in the esp. In your case i guess it would force on_turn_on to run?
Hope this helps somehow