Need help with a value_template condition

Hi there,

My solar inverter returns very awkward values when the inverter doesn’t get enough DC power to function normally. I want to overcome that with an extra condition in my value template but I’m not that good at syntaxes so need some help here.

I tried adding a and states(‘sun.sun’) is ‘above_horizon’ %} condition but that doesn’t seem to work.

      solar_live_acvoltage:
        value_template: >
            {% set root = state_attr('sensor.solar_inverter', 'root') %}
            {% if root.Device.Measurements.Measurement[0]["@Value"] is defined and states('sun.sun') is 'above_horizon' %}
                {{ root.Device.Measurements.Measurement[0]["@Value"] }}
            {% else %}
                225.0
            {% endif %}
        device_class: power
        unit_of_measurement: 'V'
        friendly_name: Netspanning omvormer

Any help would we greatly appreciated!

Regards,
René

is is the wrong test, you should be using ==. is is correct for the is defined test. But when comparing strings you want to use ==.

Hi @petro,

Thank you, that was the last thing that I missed. Now wait for the night to see if this is the best solution to overcome the awkward values.

Regards,
René

It works! The result now is that during the time the sun is below the horizon, a static value is being used.