Home Assistant - Define a switch to do something

Home Assistant - Define a switch to do something

Hi guys,

Today I want to introduce the Input Boolean integration.

It's very simple and powerful: it just allows you to define a boolean value (ON / OFF) that can be controlled via the user interface and be used in automations.

Scenario

You want to do something only if the switch defined by the input button integration is ON.

Software configuration

  1. Home Assistant. I'm currently running version?2022.9.0

Home Assistant code (yaml) / steps

  • Browse the menù?Settings?->?Devices & Services?->?Helpers?directly from the Home Assistant user interface
  • Click the Create Helper button and select the Toggle option in the list
  • You'll get this form to create your Input Boolean:

No alt text provided for this image

  • As soon as you have configured it, you can add it to your Home Assistant dashboard in order to control it:

No alt text provided for this image
No alt text provided for this image

Now it super easy creating an Automation like this one:

alias: Doing something if my toggle goes ON
description: Doing something if my toggle goes ON
trigger:
? - platform: state
? ? entity_id:
? ? ? - input_boolean.my_toggle
? ? from: "off"
? ? to: "on"
condition: []
action:
? do something
mode: single        

Some specifics about the code / procedure above

  1. The trigger is based on the changing state (from OFF to ON) of your toggle just defined. You can also define the opposite trigger (from ON to OFF) as well.
  2. Last but not least, the state of your toggle can be also set using the following service:

  • input_boolean.turn_on
  • input_boolean.turn_off
  • input_boolean.toggle

Thank you for reading. ?? I hope you have enjoyed this article.

I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below.

Your feedbacks will be very appreciated!

Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read all previous episodes and still up to date on latest news.

要查看或添加评论,请登录

Emiliano Guerzoni的更多文章

社区洞察

其他会员也浏览了