How to make a input Boolean switch?

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"

1 Like

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

1 Like

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.

1 Like

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/

3 Likes

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 :grinning:

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'
1 Like

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.

1 Like

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😂

1 Like

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.

1 Like

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.

1 Like

I didn’t know you could also say “activate” for a scene. That’s cool.

Tried that before
Here’s the result:

Creating a switch is by far the most convenient

Honestly, that makes two of us! :slight_smile: 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.

1 Like

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