Internal Switch

Hello. I need to create an internal “switch” that I can use to turn on or off depending on some events that I’m tracking within the automations.yaml. Please give me suggestions on how to code this or do this in the UI.

Thank you in advance.

Do you mean a input_boolean helper?

There are all kinds of ‘helpers’ if you need them…

Thanks Rob! I think it’s the boolean helper that is perfect for my need.

Okay. I want to initialize my input_boolean to “on” at start up but only if one condition is met else, initialize it to “off”. The code will look like this:

at start
if the porch light is "on"
   input_boolean.my_boolean set to "on"
else
  input_boolean.my_boolean set to "off"
endif

There seems to be no way to code this in the UI…

Thanks.

you need to do that using an automation with the trigger being the homeassistant start event.

You would handle it with a automation as @finity said.

But, what you seem to be creating is really a binary sensor template?

Do you plan on toggling this yourself? Or is the state (on/off) defined by other states? You could just create a binary sensor and it’ll be always up to date.

Not sure your use case so if you elaborate that might help…

Or an example through automation:

alias: New Automation
description: ""
mode: single
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - if:
      - condition: state
        entity_id: porch_light
        state: "on"
    then:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.company
    else:
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.company

Aha! It’s in UI Action that I can do if-then! Thank you so much, Rob.