I have a towel rail controlled by a Shelly switch which works fine in automation mode and I can also switch it on manually.
What I am trying to do is to have a button on a card where I can manually turn it on and have it turn off automatically after 30 minutes.
I have a script for this which I call from a button but its not working so I am looking for good advice. This is my code:
Yes possibly but I am not sure how to do the trigger, specifically the name of the button.
When I create the button, I have to assign an entity and a name.
So I named the button ‘towel_rail_adhoc’. But that name is not recognised when I try it in the automation.yaml. I get this:
trigger:
- platform: state
entity_id:
- towel_rail_adhoc String does not match pattern of "^(?!.__)(?!_)[\da-z_]+(?<!_)\.(?!_)[\da-z_]+(?<!_)$"
Any ideas?
Thanks for your help BTW. Much appreciated.
Also to reduce any confusion with buttons etc, this statement is not true, if you are referencing to creating a button in dashboard:
You can create a front end button without any reference to an actual entity by using the ‘tap’ and or ‘hold’ options like this for example: (note: no entity listed)
I tried what you mentioned about the button, that works. Thanks.
The script works now.
I have lost count of how many times I have reloaded the scripts.
I did not have ‘script: !include scripts.yaml’ in configuration.yaml. I added that and it seems to work OK now but in doing so, I seem to have created a new problem; I get error messages from some of my automations. Perhaps a problem for tomorrow.
One small ‘thing’; the button does not show the state of the device/entity.
Code for the button:
With the above button yaml as it is, it wont show a state as there is no entity listed, you are simply using a button (with no entity) and using that button to call a script in to action - so there is no entity to show the state of.
If you you want to show the state, then you need to revert back to putting the entity (either the script or the switch - as you keep changing the way you are doing it looking at the above!) in the button card and use the toggle option instead of calling a service.
Note however that if you reference the switch it will clearly show that state (‘on’ or ‘off’) however if you reference the script it will show the state when you toggle it but literally only for a split second while the script is actually running.
Relying on delays like that in automations might not be the best idea. Simply saving a new automation while that’s running well cancel it. Restarting HA will cancel it.
Imo when delays are over a few seconds or so, you should use timers or input_datetimes to make them restart safe.