I recently installed a zigbee 2 way switch to power my chicken coop door. I have two scripts, one for opening and one for closing. I am trying to create a button on the dashboard that will trigger the script.open_coop_door when pressed and change the color of the icon. And then when that button is pressed again, trigger the script.close_coop_door and set to a specific icon color.
I’ve seen some people talk about templates but I don’t know if that’s what would work for me. Any help is appreciated!
You could make a toggle helper and when you push the button have it change the state of the helper to on or off, then base your automation on doing the correct thing depending on that state.
So I started following @smarthomejunkie video on buttons and automations but only part of the video works since HA changed the automation breakdown. I did create a toggle helper labels coop door but am not sure about the automation setup with the newer stuff or what to add on the button.
Make an button card and have it run an automation or a script with what you want it to do. Use a choose action and have it check the state of the helper then if it is off it will run that section of the automation if it is on it will run the other part. Hope that makes sense
https://www.amazon.com/dp/B0B979N75C?ref=ppx_yo2ov_dt_b_product_details&th=1
It’s a 2 channel switch. I have running a linear actuator so one switch extends the actuator, the second switch retracts so it’s technically two independent switches and thereby have to have two separate scripts. One to extend, one to retract.
In this example it would look at the toggle for my dremview and turn a light on or off. You can have it look at any state and run whatever actions you want. Then set your button to run the one script on every press.
At the end of that script have it toggle your helper so that the next button press will do the alternate option.
then create your lovelace button card pointing to just switch.zigbee_switch_1
you can also of course use tom_l’s suggestion of a template switch which is a bit more elegant perhaps. but i think this works and is simple if my assumption above is right.
So script.open_coop_door triggers one independent switch to turn on (retracting the linear actuator) and then turn off 20 seconds later. script.close_coop_door triggers another independent switch to turn on (extending the linear actuator) and then turn off 20 seconds later. Triggering one switch does not automatically turn off the other.
I need the scripts to thereby turn off the switch 20 seconds after the switch has turned on because thats how long it takes to open or close the door.
If you share the config for those two scripts it you will possibly be able to replace all of this with just the template switch:
Your automation,
the Input boolean,
the two scripts.
switch:
- platform: template
switches:
skylight:
turn_on:
- service: script.open_coop_door # or put your script sequence here and delete the script
turn_off:
- service: script.close_coop_door # or put your script sequence here and delete the script
Now there is currently no state feedback (value template) so the switch will be operating in “optimistic” mode. That means if you operate the door with the physical remote it will get out of sync with the state shown in home assistant. This is also a problem for your automation and input boolean. The only solution is to hide the remote.
No state feedback is the main problem of 433RF and IR devices. There are better options but it is a bit late for that now.
Edit: actually after reading that product description it has wifi too so you may be able to get state feedback with the Tuya integration.