Boolean State Follower

It is often useful to set the state of one entity based on another. Maybe one light should be turned on when another light is on. Or a template helper computes the desired state of a switch.

Unlike the example in the blueprint tutorial, the Boolean Follower only requires its input to have a state which can be ‘on’ or ‘off’, and the entity which is supposed to match that state must have a ‘turn_on’ or ‘turn_off’ service.

If the input state is other than on or off, the automation will fail, which I think is the desired behavior.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Boolean Follower
  description: An entity with turn_on and turn_off follows the state of another entity with on or off states.
  domain: automation
  input:
    to_follow:
        name: Entity to Follow State
        description: The entity with the desired state.
        selector:
            entity:
 
    target_entity:
      name: followed
      description: The entity that should bept in sync with the entity to Follow State
      selector:
            entity:

mode: restart
triggers:
  - trigger: state
    entity_id: !input to_follow

actions:
  - action: homeassistant.turn_{{ states(trigger.entity_id) }}
    metadata: {}
    data: {}
    target:
      entity_id: !input target_entity

As an example of a way I use this, I have a complicated set of circumstances in which I want my holiday lights on.

If it is dark out any any of this are true:

  • time between 6AM and 10:30PM
  • person detected by frigate
  • someone is arriving home

or my outdoor light switch for another set of lights is on (mainly to force the lights on during day for testing).

I compute that with a template helper, and turn on a group of lights with the blueprint (I have two switches that need to be operated).

@dougransom Hi Doug, I found this while looking for a way to sync my a lock entity (locked or unlocked) with a binary_sensor entity (on or off)

Any chance you can mod the blueprint to work in this situation?

thx!

I’ve recently started getting errors with this Blueprint. Not sure what can be done about it but I thought I would share:

onn Google Media Player bool tracker uses an unknown actionError · Reported by Automation

The automation “onn Google Media Player bool tracker” (automation.onn_google_media_player_bool_tracker) has an unknown action: homeassistant.turn_unavailable.

This error prevents the automation from running correctly. Maybe this action is no longer available, or perhaps a typo caused it.

To fix this error, edit the automation and remove this action.

Select Submit below to confirm you have fixed this automation.

I switched to using the blueprint Linked Entities , you might want to try that.

Edit the blueprint & add in a condition that the trigger state is not unavailable.

Sugestion:

The turn_{{ states(trigger.entity_id) }} error occurs in Home Assistant Community because you are likely trying to use trigger.entity_id directly within a service call, but you should instead use trigger.to_state.state to get the new state of the entity. The error message turn_unavailable or turn_unknown indicates that the automation is trying to call an invalid service because the trigger.entity_id is being rendered as part of the service name, which is incorrect syntax.

Correct Syntax

To fix this, use trigger.to_state.state in your template to correctly identify the new state of the triggered entity.

For example, instead of:

Code

action:  service: input_boolean.turn_{{ states(trigger.entity_id) }}

Use:

Code

action:  service: input_boolean.turn_{{ trigger.to_state.state }}

Stop blindly posting what AI tells you and read my previous comment above.

Using trigger.to_state.state won’t solve the issue since it will render as unavailable if the trigger state goes to unavailable.

The only way to fix this is to either use not_to / not_from unknown/unavailable in the trigger, or else by excluding those states in a condition.

Because this one was accepted by home assistant as a repair and the other one not