Help with open close automation

Hi all,

I have the following automation which works .
if the binary sensor opens (it is my door) the shelly turns on too. How can I reverse the action of the shelly in order to turn off when the door opens?

I think I could have 2 different automations or approach it with another way, but could I change the particular automation?

- id: 'Paradox my sensors' 
  alias: Paradox my sensors
  trigger:
  - platform: state
    entity_id: binary_sensor.openclose_30
  action:
  - service: "switch.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: switch.shelly1_c45
- id: 'Paradox my sensors' 
  alias: Paradox my sensors
  trigger:
  - platform: state
    entity_id: binary_sensor.openclose_30
  action:
  - service: "switch.turn_{{ 'off' if trigger.to_state.state == 'on' else 'on' }}"
    target:
      entity_id: switch.shelly1_c45
2 Likes

I was sure it could be done. Thanks!