Can i make a condition to trigger entity based on the state of the same entity?

Hi,

I m trying to trigger the sonoff to turn on fan, based on motion. But as i dont want it to keep triggering the automation as it will always sense motion if i m around.

So i m trying to put condition where it will only trigger if the fan is off.
These are my codes, but it doesnt work. got error on indent, cant even save. I double checked the code, it seems correct to me.

- id: Fan on motionHall
  alias: Fan On when Hall Movement
  trigger:
  - entity_id: binary_sensor.motion_sensor_158d000128bd6c
    platform: state
    to: 'on'
    condition: state 
      entity_id: 'switch.sonoff_10003c390a'
      state: 'off'
  action: 
  - service: switch.turn_on
    entity_id: switch.sonoff_10003c390a
  - service: media_player.alexa_tts
    entity_id: media_player.echo_hall
    data:
      message: Fan turned on.

almost correct, you’re missing the condition: header:

- id: Fan on motionHall
  alias: Fan On when Hall Movement
  trigger:
  - entity_id: binary_sensor.motion_sensor_158d000128bd6c
    platform: state
    to: 'on'
  condition:
  - condition: state 
    entity_id: 'switch.sonoff_10003c390a'
    state: 'off'
  action: 
  - service: switch.turn_on
    entity_id: switch.sonoff_10003c390a
  - service: media_player.alexa_tts
    entity_id: media_player.echo_hall
    data:
      message: Fan turned on.

that did it!
I swear i ve went through that code soooo many times, and still couldnt spot this!

Thanks a bunch!

1 Like