I need to create a input Boolean switch. I have a mi ac partner to trigger IR command. I can do it by calling a service on type the JSON data. I want to create a switch to add to the ui. I cannot use template switch because there is no sensor to tell the state of the device.
I canât tell if your indenting is wrong or not, because you havenât used the proper code formatting feature (see the blue box at the top of the page), but hereâs the config for my command line switches. In YAML, proper indenting is imperative.
However, at first glance, what it looks like is that youâre trying to use scripts as the command lines. This isnât going to work. You will have to specify the actual command lines in the âcommand_onâ and âcommand_offâ sections.
- platform: command_line
switches:
livingroom_tv:
command_on: /home/hass/config/ircommand.sh --command "LivingRoomTV,PowerOn"
command_off: /home/hass/config/ircommand.sh --command "LivingRoomTV,PowerOff"
recroom_tv:
command_on: /home/hass/config/ircommand.sh --command "RecRoomTV,PowerOn"
command_off: /home/hass/config/ircommand.sh --command "RecRoomTV,PowerOff"
I have two script called Fan On and Fan Off
command_on: /home/hass/config/ircommand.sh --command "LivingRoomTV,PowerOn"
command_off: /home/hass/config/ircommand.sh --command "LivingRoomTV,PowerOff"
How it should look like based on the format above? I mean how to call the Fan On and Fan Off script? New to theseâŚ
I have checked my indenting and nothing wrong
Is LivingRoomTV,PowerOn and LivingRoomTV,PowerOff your command in the file ircommand.sh ? Maybe I understand a little here
Yeah, that is just a bash script I wrote to control some infra red devices. Replace that part with whatever the command line is that controls your devices.
Thanks, but I need to create a input Boolean switch because command line switch donât work for me
I do that very thing.
input_boolean:
heatpump_upstairs_power:
name: Heat pump upstairs power
switch:
heatpump_upstairs_power:
value_template: '{{ states("input_boolean.heatpump_upstairs_power") }}'
friendly_name: 'Upstairs heat pump power'
turn_on:
- service: input_boolean.turn_on
entity_id: input_boolean.heatpump_upstairs_power
- service: shell_command.heatpump_upstairs_mode
turn_off:
- service: input_boolean.turn_off
entity_id: input_boolean.heatpump_upstairs_power
- service: shell_command.heatpump_upstairs_mode
And then I define my shell_commands using this documentation: https://www.home-assistant.io/components/shell_command/
It helped! Thanks! I think home assistant should remove the requirement of value_template in the template switch. It should be optional. It creates a lot of hassle to beginners like me
If you didnât have the value_template, then the boolean would be useless, and youâd essentially have a command line switch anyway. (which is exactly what you had before?).
I havenât tried it, but you might be able to have something like this:
value_template: {{ false }} # switch always appears 'off'
or
value_template: {{ true }} # switch always appears 'on'
I am using IR blaster to make a switch turn on/off the fan. Since IR has nothing to tell and the state of the fan and âOnâ and âOffâ are just the same command. In this case, value_template has no function at all.
I know you will just tell me to create a script and activate it but I have Google Assistant intergrated. Google Assistant donât do well with script with similar names. (In this case Fan.On and Fan.Off script)
I feel like weâre trying to fit a square peg into a round hole. The real issue is that you have no way of really knowing what the state of your fan is. If you want to pretend to have a state, then you have to back your switch with an input_boolean. Otherwise, youâre right, I would recommend just having a script to toggle the fan, and donât pretend to know what state itâs currently in. Donât even have two scripts, if theyâre the same command anyway. Just call it âToggle fanâ or something.
If value_template is not required, it will be:
```
switch:
- platform: template
switches:
whatever switch:
turn_on:
service: switch.turn_on
turn_off:
service: switch.turn_on
```
It will save beginner like me lots of time researching and asking forumđ
Tried that before, Assitant will just tell there is no turn off command to turn off the fanâŚ
Anyway, thanks for your reply !
Yeah, Google assistant is kind of dumb that way. When itâs a script, you always have to say âTurn Onâ to run it. So turning on or even turning off the fan (which would really be just a toggle, not a discrete âturn offâ) youâd have to say âHey Google, turn on toggle fanâ or whatever you called your script.
I think thatâs a Google assistant problem, not home assistantâs.
Perhaps not so âdumbâ because a script can only be activated, not deactivated, so âturn onâ is all thatâs applicable. The Assistant cannot determine the scriptâs actual function (turning a fan on/off, increasing/decreasing volume, etc) all it knows is to set it in motion.
Hereâs another solution, create two scenes, one called Fan On and the other Fan Off. Then you can say âHey Google, activate fan onâ and âHey Google, activate fan offâ. Yeah, still clumsy but there it is.
I didnât know you could also say âactivateâ for a scene. Thatâs cool.
Honestly, that makes two of us! I donât even own one but found this link:
Itâs entirely possible that document is incorrect. Perhaps someone who owns a Google Home/Mini can confirm if âactivateâ is valid.
Heh. Because you can also say âTurn onâ for a scene, itâs matching âfanâ to two scenes and running both.
In your screenshot, I donât see evidence of you using the word âactivateâ to initiate the scene.
The Assistant should understand me, not I understand the assistant
Well well all of the solutions work and thanks for all of your replies