Need help with a Blueprint/Automation

This is what I want to accomplish:

When an input.boolean change its state to TRUE/ON then it should turn on switch “A” and 15 seconds after “A” is confirmed turned on it should turn on switch “B”.
And when the nput.boolean change its state to FALSE/OFF hen it should turn off switch “B” and 15 seconds after “B” is confirmed turned off it should turn off switch “A”.

Is there a Blueprint like that or do I need to learn how to do one by myself?

There appears to be a lack of symmetry. Is that intentional?

  • When the input_boolean turns on, both switches get turned on.
  • When the input_boolean turns off, both switches don’t get turned off, only switch B (switch A is turned on).

God catch ! copy paste error Updated

Give this a try (modify the entities to match what you are using):

alias: example 999
trigger:
  - platform: state
    entity_id: input_boolean.test
action:
  - variables:
      is_on: "{{ trigger.to_state.state == 'on' }}"
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: "switch.{{ 'switch_a' if is_on else 'switch_b' }}"
  - delay: '00:00:15'
  - service: "switch.turn_{{ 'off' if is_on else 'on' }}"
    target:
      entity_id: "switch.{{ 'switch_b' if is_on else 'switch_a' }}"

What I posted doesn’t explicitly confirm that a switch has changed to the desired state. It simply assumes the switch complies with the command, pauses for 15 seconds, and then sets the next switch’s state.

If you really want it to check and confirm that the switch has changed to the desired state, it will require a bit more sophistication.

Thank you I give it a try

Didn’t work. Ended up doing two automationes, one for ON and one for OFF

You’re right, I made a mistake in the second service call. Instead of this:

  - service: "switch.turn_{{ 'off' if is_on else 'on' }}"

it should be this:

  - service: "switch.turn_{{ trigger.to_state.state }}"

I tested the following version and can confirm it works properly. Simply set the variables first and second to the names of your two switches.

alias: example 999
trigger:
  - platform: state
    entity_id: input_boolean.test
action:
  - variables:
      is_on: "{{ trigger.to_state.state == 'on' }}"
      first: 'switch_a'
      second: 'switch_b'
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: "switch.{{ first if is_on else second }}"
  - delay: '00:00:15'
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: "switch.{{ second if is_on else first }}"

Ok as a newbie on this Thanks :slight_smile: The other questian Can I make a Blueprint out of this and change:

 - variables:
      is_on: "{{ trigger.to_state.state == 'on' }}"
      first: 'switch_a'
      second: 'switch_b'

to

  • variables:
    is_on: “{{ trigger.to_state.state == ‘on’ }}”
    first: !input target_zon1
    second: !input target_zon2

And further down
target:
entity_id: “{{ first if is_on else second }}” // I.e. remowe switch.

Not home right now so I can’t test myself :slight_smile:

Yes. It would look something like this:

action:
  - variables:
      is_on: "{{ trigger.to_state.state == 'on' }}"
      first: !input switch_a
      second: !input switch_b
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: "{{ first if is_on else second }}"
  - delay: '00:00:15'
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: "{{ second if is_on else first }}"

Thank you for your big help :slight_smile:

1 Like

You’re welcome!

Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It also puts a link under your first post that leads to the Solution post. All of this helps users find answers to similar questions.

Couldn’t hold myself. Connected to my HA and tested it.

get some errors:

Triggered by the state of input_boolean.irr_zon1 at July 28, 2021, 3:38:56 PM

Define variables is_on, first, second

Call a service based on a template on templated entities

Stopped because an error was encountered at July 28, 2021, 3:38:56 PM (runtime: 0.01 seconds)

Template rendered invalid entity IDs: {‘entity_id’: ‘switch.devzone1’}

I have a entity named switch.devzone1 with friendly_name: devzone1

But it seems like it cant find it.

Here is the complete Blueprint


blueprint:
  name: Irrigation pump control
  description: Turn on the Irrigation relay and the pump 15 seconds after valve is opened
  domain: automation
  input:
    selected_switch:
      name: Irrigation Helper
      description: Choose the entity of the Helper 
      selector:
        entity:
          
          
    target_zon:
      name: Irrigation Switch
      description: The actual irrigation valve switch.
      selector:
        target:
          entity:
            domain: switch
    target_pump:
      name: Irrigation Pump
      description: The irrigation pump connected to above valve.
      selector:
        target:
          entity:
            domain: switch

trigger:
  - platform: state
    entity_id: !input selected_switch

action:
  - variables:
      is_on: "{{ trigger.to_state.state == 'on' }}"
      first: !input target_zon
      second: !input target_pump
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: "{{ first if is_on else second }}"
  - delay: '00:00:15'
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: "{{ second if is_on else first }}"

That’s because your blueprint specifies target_zon and target_pump as a target instead of an entity_id. As a result, the variable first gets set to this:

{'entity_id': 'switch.devzone1'}

instead of this:

'switch.devzone1'

Change your code to this:

  input:
    selected_switch:
      name: Irrigation Helper
      description: Choose the entity of the Helper 
      selector:
        entity:
          domain: input_boolean
    target_zon:
      name: Irrigation Switch
      description: The actual irrigation valve switch.
      selector:
        entity:
          domain: switch
    target_pump:
      name: Irrigation Pump
      description: The irrigation pump connected to above valve.
      selector:
        entity:
          domain: switch

Thanks another copy and paste mistake. It solved it and it works perfectly