So, with the release of 0.46, I am getting these fun warnings WARNING (MainThread) [homeassistant.components.automation.state] ‘state’ is deprecated. Please rename ‘state’ to ‘to’ in your configuration file.
I have multiple automations using this, and frankly, neither the warning message or the component documentation are any help here. Changing from ‘state’ to ‘to’ makes no sense.
# Turns on lights at sunset
- alias: 'Candle Lights on'
trigger:
# Prefix the first line of each trigger configuration
# with a '-' to enter multiple
- platform: sun
event: sunset
offset: '-00:10:00'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.holiday_mode
state: 'on'
action:
service: homeassistant.turn_on
entity_id: group.candle_lights
I don’t understand this at all. The documentation from the release notes leads to a 404, the above explanation isn’t clear to me, and my logs are unhelpful. I’m not sure which policy is failing on my system.
The key was looking just at the trigger portion of the automation. I had the same problem with the use of ‘after:’ in some triggers and was also able to track those down.
@amelchio gave me this link in the comments to the issue that prompted the PR and it may help you to understand it better; I know it helped explain it to me:
I think the reason that I liked the previous method better, was that I don’t want to list all possible ‘from’ states in the trigger, and it just doesn’t look right only listing a ‘to’ state.
So while this works, it is a little odd.
- alias: 'Christmas Tree on'
trigger:
- platform: state
entity_id: sun.sun
to: 'above_horizon'
If I want to trigger on a specific state change I can use "to and “from”.
If I want to trigger on a state change ending state I can use “to”
If I want to trigger on a state change starting state I can use “from”
It allows me to do everything I need to do and in a logical way.
I typically am explicit in my triggers and use to and from; unless more general behavior is needed.
Those are identical if you only have two possible states (like on/off) because any change to a state must be coming from the other.
If you have more than two states (like playing/paused/idle), omitting from will make the lone to match any change to that state, no matter where the state is coming from.