Automation on sun attributes not working

I want to trigger my automation when the sun gets past the zenith so I tried when sun rising changes from true to false:

platform: state
entity_id:
  - sun.sun
attribute: rising
from: 'true'
to: 'false'

but the automation never runs, no errors in the logs and no traces.

I tried also with azimuth and height attributes and without the from, same effect. I think I’m following according to Triggering on other attributes section on the docs but I don’t know what I’m doing wrong.

any pointers would be deeply appreciated :slight_smile:

By the way, doing this on a pi 3B+, with Home Assistant Core 2022.6.6

have you waited for the “rising” attribute to transition from true to false?

So if the “rising” attribute is already false then the trigger never fires.

I am pretty sure it is evaluating to a boolean. and your ‘from/to’ is a in quotes making it a string. Try this:

platform: state
entity_id:
  - sun.sun
attribute: rising
from: true
to: false

You can test it by going into the developer tab and manually changing the sun.sun sensor attribute from false to true or true to false in the ‘set states’ section in the states tab… No need to ‘wait’ till tomorrow.

You can plug this into the developers tab template and see if it works correctly too and if its a ‘boolean’.

{{ states.sun.sun.attributes.rising == false }}
{{ states.sun.sun.attributes.rising == true }}
{{ states.sun.sun.attributes.rising == 'false' }}
{{ states.sun.sun.attributes.rising == 'true' }}

output:

True
False
False
False

I checked and its a boolean… You can see above it is also…

1 Like

@calisro Nice! that got it working, thank you so much :+1:
You know I though of checking ‘FALSE’ vs ‘false’ but not if it was taken as a string or boolean.