I have a script for turning on my sprinkers, where it creates a sequence of actions including turning on a switch but also using a delay which is a input_number before turning off.
Obviously the turn off function either needs to be the switch directly, or call a different script, but it would be a different script then the turn on script.
How do we tell google assistant to differentiate the turn on, vs the turn off scripts ensuring it calls the right scripts?
Thanks to you both.
i created a switch template - dont know if it will work until tomorrow. I’ll use these switches which in turn call the necessary script. Hopefully it works but will report back tomorrow.
It needs a value_template which returns true or false - and creates a slider switch - but I don’t know what the current state is and would rather have two on/off buttons.
You could define two switches, which does not have areal value template, but rather an ‘Off’ template.
That way you can initiate the switch and it will return to off state afterwards.
For example I use that for the Google Assistant sync:
Thanks but that won’t quite do what I want, I have a script which turns on all the tv stuff (amp, sky box, set inputs) and one that turns them off. So if I define a switch called ‘tv’ which calls those scripts for on/off then I can say to Google Home ‘turn on tv’ or ‘turn off tv’ and we’re good.
Hardcoding the state to false is ok for Google but the UI has a slider switch which is useless half the time.
Using a template switch is a way to do what your describing. It took me a little while to figure it out. You need to make sure that you set the correct type for the switch in the customize.yaml file
Heres what I use to turn on and off the nintendo switch activity on my harmony remote
@Orthodoxmonster What happens when someone changes the TV’s input but leaves the Nintendo on? media_player.hdmi_8 will be off which will flip the switch in your UI to ‘off’ so you won’t be able to turn it off again?
Is yours a - platform: template switch or is your yaml complete and there’s a way to define a switch I can’t find in the docs?
It doesn’t usually turn it to off, but for my use it doesn’t need to. All I care about is whether the correct harmony activity is active.
define your “template switch” as a switch in your customize.yaml for google assistant purposes. like in my example
So I created a template switch named “nintendo switch” that runs scripts depending on the template switch’s state. Then in the customize.yaml I define that template switch as a switch for google assistant purposes. google_assistant_type: switch
I’m not sure if you’ve actually tried it, or if this will change in the future, but asking google to turn something on/off just recalls the on/off script regardless of the switch’s actual state. So you can activate ‘on’ again, even if the switch in currently at ‘on’.
But on the UI I have a toggle switch that is stuck in the wrong position. I’d prefer it if they were two buttons but being forced to return a true/false value makes it a toggle switch.