I have two separate buttons that arm and disarm my alarm control. I am wondering if someone can point me in the right direction on how to do that create one button that will toggle the alarms state. Below is the code for my button that arms my alarm. How can I create a custom service that based on the state of my alarm, toggle it to either armed_home or disarmed? I have never created a script or a service and don’t even know where it would go, or what it would look like.
Thanks,
type: 'custom:button-card'
entity: alarm_control_panel.home_alarm
state:
- value: disarmed
icon: 'mdi:shield-home'
color: red
name: Alarm off
- value: armed_away
icon: 'mdi:shield-home'
color: green
name: Alarm On
tap_action:
action: call-service
service: alarm_control_panel.alarm_arm_home
service_data:
entity_id: alarm_control_panel.home_alarm
code: 7777
hi there… to create a script for this, we need to goto configuration>script>add new script.
for now i have created a script for you, it should work but if not we may need make some changes to it.
Thank you Very much, this was very helpful. I was able to get the script created with a bit of tinkering, and it works flawlessly as expected when I execute the script manually. However, when I call the script from my button I get an error that states “Failed to call service script/alarm_toggle. Service not found.” . I was a bit confused about the name of the script(Alarm Toggle) and why the call of the script was alarm_toggle. They don’t match, and I tried to tinker with them but no help at all.
It shows up as a numbered script. When I execute this service, it arms and disarms my alarm system just like iut should. Sadly though, I changed the script name in the button from and I still get the following message. I thought this would have been easy to do, you know calling a script from a button, had to have been done a thousand times. Maybe there us an alternative solution? I basically am looking to build ONE button that will arm/disarm my alarm_control_panel system.
“Failed to call service script/161728095085. Service not found.”
Thanks, but that change produces the same error, where it cannot find the service. I have tried many different formats, without success. Seems like this would be simple.
I have tried it with my system and it works fine. Do one thing, Please delete the script.161728095085 from your HA and create a new one like that and try. Also please remove the underscore from the alias and use it like this.
OMG! You are a lifesaver, it is working after deleting and re-adding the script! I am not even going to look back, that script must have been corrupt or quite possibly it was the alias name causing the issues. Either way, it is working now and I thank you very much.
Just want to chime in here that this process got me to the result I was looking for was well. I have a hi-fi system that does not have remote power control. I bought some smart power strips to enable me to power on the system rather than having to reach around to the back of each piece. The sequence is important as well as sources power on when the amps are running can trigger some popping through the speakers. So, I was able to write 2 scripts one with the power on sequence, another with the power off. Then I added a button to call each on my dashboard. This worked but looked terrible.
I used this process to combine the 2 scripts with the ‘choose’ condition and the state of one of the outlets triggering either the on or off sequence. The custom button card works perfectly , changes from looking like a power on icon when the system is off to a power off icon when the system is on.
Thanks so much and I really gained some deeper understanding about how all of this stuff works. I cranked up some happy tunes starting with powering on my system with my new button thanks to you.
I know this is an old topic but I stumbled onto this when googling around why my button gave me a service not found when it should invoke a script that certainly does exist. I managed to find the reason for the error before deleting and recreating the script. Actual cause, in my case at least, was that I had renamed the script entity. Renaming the entity however does NOT change the name in scripts.yaml that lives in your config folder. So edit that file, change the name there to match your script entity’s new name and reload yaml configurations, and it should work.