Automation - sun rising attribute as condition

Hello All, I need a little help here. I am having a Z-Wave Lux Meter through Fibaro as Trigger, no issue with it.
Then I have the sun.sun rising attribute which I expect to be false in a condition. Now this is not working. I checked, it is false but my automation breaks at the condition telling me that condition not met.
Below is my YAML entry. What should I do to make it work?
‘’’
trigger:

  • platform: numeric_state
    entity_id: sensor.hatso_udvar_flood_light_lux_107
    below: ‘200’
    condition:
  • condition: state
    entity_id: sun.sun
    attribute: rising
    state: ‘False’
    action:
  • scene: scene.esti_megvilagitas
    mode: single
    ‘’’

Try this:

alias: 'Example 1'
trigger:
  - platform: numeric_state
    entity_id: sensor.hatso_udvar_flood_light_lux_107
    below: 200
condition:
  - condition: state
    entity_id: sun.sun
    attribute: rising
    state: false
action:
  - service: scene.turn_on
    target:
      entity_id: scene.esti_megvilagitas
mode: single

It can also be done like this:

alias: 'Example 1'
trigger:
  - platform: numeric_state
    entity_id: sensor.hatso_udvar_flood_light_lux_107
    below: 200
condition:
  - condition: template
    value_template: "{{ is_state_attr('sun.sun', 'rising', false) }}"
action:
  - service: scene.turn_on
    target:
      entity_id: scene.esti_megvilagitas
mode: single
1 Like

Thank you my friend! It was obvious and worked. I only needed to remove the ’ before and after the “False” and switched it back to “false” as it was originally. But come on! Why Home Assistant is formatting the YAML entry wrong? Why is it putting the ’ mark before and after the state? I don’t get it.
I was also creating a binary sensor with template, if your solution would have failed I would have used that dummy sensor.
So Home Assistant Developers: Please make sure the graphic interface of automation is working well and creating the YAML entry properly. If it is a binary state, make it a binary state in YAML.

The Automation Editor UI doesn’t compare what you enter with the type (integer, boolean, float, list, dict, etc) of an entity’s value. It simply assumes whatever you enter is a string. In other words, there is no ‘type checking’ performed on data entry.

The reason for this is because all state values are always strings. Only attributes can have a type other than string but most use string. If you want to check if an attribute is a string you can test it using a template like this in the Template Editor (example shown for sun.sun):

{{ state_attr('sun.sun', 'next_rising') is string }}

In this case it will report True which confirms the value in next_rising is a string.

1 Like

Got it, thanks!