Automation: stat_attr in condition?

Hi everybody,

I am trying to create an automation to switch on a certain light when (a) there is motion and (b) illuminance is beneath a certain value.

trigger:
  - platform: state
    entity_id: binary_sensor.motion_kueche_occupancy
    to: "on"
condition:
  # what goes here?
action:
  - delay: 00:00:02
  - service: switch.turn_on
    entity_id: switch.kueche_schranklicht

I would like the light to only turn on when {{ state_attr('binary_sensor.motion_kueche_occupancy', 'illuminance') | int < 12}} is true. How can I implement this in my condition?

This is difficult to test because the sensor will keep occupancy = on for ~2min before resetting. So each time I change and test something, I have to wait… even if I manually change the value in development tools, the sensor itself will not transmit again until the timeout has been reached.

Thank you for your help :slight_smile:

You’re looking for a value_template as a condition I believe. Here’s a thread that discusses something similar to what you’re after I believe: Automation value template assistance

Should be good with this:

condition:
  condition: template
  value_template: "{{ state_attr('binary_sensor.motion_kueche_occupancy', 'illuminance') | int < 12 }}"
1 Like

Thank you so much!

No problem! Also, this is a good read for more info on conditions.

1 Like

Thank you. I had read that previously (before posting here), but while I understand which template I should use, I could not figure out how to construct it.