How to set input_boolean to value of another input_boolean

Fairly new to HA, and haven’t found a related post (or don’t know keywords well enough yet):

Here’s my technical question: how do I assign one input_boolean to the value of another input_boolean?

Use-Case: I have scripts for school-mornings, to help get kids up-and-going. Easy to run M-F, and even exclude holidays, days off, etc. But sick kids don’t follow that rule, nor conference days I forget, etc. I want to temporarily disable the automation for the NEXT day’s activities, aka, set and test for an input_boolean. The trick is, I don’t want to limit WHEN I can set that boolean… the night before, in the morning during breakfast, etc. But always for the NEXT day’s activity.

This really means I have 2 booleans: one for input_boolean.school_today (hidden), and one for input_boolean.school_tomorrow. At some point, I need to set Today == Tomorrow, then reset Tomorrow to some new default. I chose 3am as that cross-over point (later than I ever go to bed, earlier than I ever get up).

From ./automations/set_school_tomorrow_flag.yaml:

alias: Set School Tomorrow Flag
initial_state: true

trigger:
  # at 3am
  - platform: time
    at: '03:00:00'

action:
  # need help here... how do I:
  - set: input_boolean.school_today == input_boolean.school_tomorrow

  # this works fine:
  - service: script.turn_on
    entity_id: script.set_school_tomorrow_boolean

The script.set_school_tomorrow_boolean contains logic to determine M-F, holidays, scheduled days off, etc., and is working fine. But I don’t know how to assign one boolean to the value of another.

Or… is there another way to solve this requirement besides booleans?

Thanks!

1 Like

This automation should do the trick. At 3 am it will set todays, then right after it will reset tomorrow (so you don’t have to turn tomorrow on every day).

- alias: Set Todays flag at 3 AM
  trigger:
    - platform: time
      at: '03:00:00'
  action:
  - service_template: "input_boolean.turn_{{ states('input_boolean.school_tomorrow') }}"
    entity_id: input_boolean.school_today
  - service: input_boolean.turn_on
    entity_id: input_boolean.school_tomorrow

What it’s doing is using a service_template. A {{ template }} is where you can extract information out of a entity using Jinja2 (a code language based on python). In this case we are extracting the state of an input boolean, which will be ‘on’ or ‘off’. Then due to the placement of the {{ template }}, it will concatenate the state with the string "input_boolean.turn_". In the end, our service will be either input_boolean.turn_on or input_boolean.turn_off, which is based on the state of input_boolean.school_tomorrow.

3 Likes

Ah… I see what you did there - take advantage of the fact that all an input_boolean’s possible states happen to match the service call. Clever :slight_smile:

Not the answer I was expecting, but I’ll take it! Thank you!

1 Like