I thought I had this all figured out but HASS has thrown me another curve ball.
I have a seemingly simple automation that turns on a light if a camera detects motion as long as it’s NOT summer and during a certain time. But what I’m finding based on the trace for the automation is it’s actually evaluating the NOT part the opposite. I’m looking for season.season to NOT be summer but it seems to be evaluating it like I want it to be summer. And I don’t see whats wrong with the way the conditions are set up:
try removing the not condition and explicitly look for the states you want for the sensor. example:
- condition: state
entity_id: sensor.season
state:
- spring
- autumn
- winter
EDIT: also the trace appears to be evaluating the season sensor condition correctly. it is looking for the sensor state to be summer and it is currently autumn so the condition evaluates as false. but the not just before it doesn’t appear to be evaluating as it should. and actually if I’m reading the trace correctly, the not condition does evaluate as true.
not → conditions/1
season → conditions/1/condition/0 and conditions/1/condition/0/entity_id/0
The trace shows the results for the State Condition and for the Not Condition. You’re misreading the State Condition. It correctly indicates false (it’s currently autumn, not summer). You should be looking at the result of the Not Condition which is correctly reporting true. The upshot is that the combination of the two conditions is doing exactly what you requested: allow for every season exceptsummer.
Replacing the State and Not conditions with a single State Condition may make it more comprehensible for you but the end-result is that it will work identically to what you already have now. It doesn’t “fix” anything, it just rearranges the logic but the final result is the same.
If it makes it clearer for you, here are the equivalent conditions implemented as Template Conditions in shorthand notation:
- "{{ not is_state('sensor.season', 'summer') }}"
- "{{ states('sensor.season') in ['spring', 'autumn', 'winter'] }}"
That’s just another way of providing a list of states the sensor should evaluate as true. However, it appears it is explicitly looking for the state to be “autumn,winter,spring” in which case, that will never evaluate as true. Switch back to the not condition with season sensor. Also, why are you putting a condition of type trigger and the id of this automation in the conditions section? remove your first condition and try again. Also, you can move your conditions from the choose/action section up to your actual condition section.
Try this automation
alias: Security - Backyard Motion Detected - Turn On/Off Light - Not Summer
description: ''
trigger:
- platform: state
entity_id: binary_sensor.motion_backyard
from: 'off'
to: 'on'
condition:
- condition: not
conditions:
- condition: state
entity_id: sensor.season
state: summer
- condition: time
after: '20:00:00'
before: '07:00:00'
action:
- service: homeassistant.turn_on
target:
entity_id: switch.backyard_floodlight
mode: parallel
max: 10
That’s a known problem with the Automation Editor. If you compose a State Condition with a proper list in YAML, it converts it to a comma-separated string (which effectively breaks the State Condition). I believe this bug has already been reported as an Issue in the Frontend repository (on GitHub).
Just revert to using your original State and Not Conditions.