Hi, I’m trying to use command line to create a switch that help me to turn on my Broadlink TC-2 which is a RF switch. I had written a script to turn on or off the TC-2 and it work. Now I want to create a virtual switch so I can use in my Floor Plan as a normal switch that toggle and also change the floor plan picture to bright or dark as per the state of the switch. My config as below :
Is this possible with Scripts? Where to insert the scripts? Inside the value of the template? What put in entity_id? Sorry, I’m very new to HA. Just 2 weeks into this.
The value_template is used for feedback to home assistant to tell it the state of the switch. Without this you will have two buttons, one to turn the switch on, one to turn it off, rather than a toggle switch.
You can use customize to change the icon if you wish.
I don’t think self referencing like this to obtain the state will work.
Consider this:
The switch state is off and the Lovelace button reflects this state.
You tell the switch to turn on by toggling the Lovelace button and the script.power_on_wardrobe script is called.
Home Assistant checks the value_template to see what the state of the switch is.
The switch state is still off (as the value template has not updated).
So the Lovelace switch button turns off again.
You could turn on/off an input_boolean in your on/off scripts and check that state in your value_template.
However this will get out of sync if you have any other method to control the wardrobe light other than the scripts (a physical remote control for example).
If this is likely to be the case your only option is to remove the value template so Lovelace has separate on/off buttons and no state representation for the wardrobe switch.
Unless you have a way of actually getting the state of the switch back into home assistant.
Ok. I understood now. Will add input boolean in the script. As there is no way I can get the state from the switch because this is RF switch, I will hv to live with the possibility of out of sync. Thanks for your help.
Although the switch works but I received the following error:
Wardrobe Light: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data[‘entity_id’]
8:46:17 AM – helpers/script.py (ERROR) - message first occurred at September 19, 2020, 10:04:33 PM and shows up 12 times
power_off_wardrobe: Error executing script. Invalid data for call_service at pos 2: not a valid value for dictionary value @ data[‘entity_id’]
8:46:17 AM – Script (ERROR) - message first occurred at September 19, 2020, 10:04:39 PM and shows up 6 times
power_on_wardrobe: Error executing script. Invalid data for call_service at pos 2: not a valid value for dictionary value @ data[‘entity_id’]
8:46:12 AM – Script (ERROR) - message first occurred at September 19, 2020, 10:04:33 PM and shows up 6 times