Determination of a state_attr when it is null

I have an entity with a state “off” and current attributes:

The attribute I’m interested in shows:

Screenshot_20240202_140020_Home Assistant

If I enter

{{ state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time') }}

in the template editor I get

null

If I enter exactly the same a second time, so:

{{state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time') }}
{{state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time') }}

I get

None
None

Why does the state_attr change from “null” to “None” when I enter the same thing twice?

Also, if I enter:

{{ is_state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time','null') }}

or

{{ is_state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time','None') }}

I get “false”

Trying to figure out how to bypass this line:

{{as_timestamp(state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time'))|timestamp_custom ('%H:%M %p') }}

in a template when the result renders “None” due to the “null” state of the attribute.

That’s an artefact of the Template Editor rendering.

{{ state_attr('binary_sensor.octopus_energy_target_intermittent_best_rates_total_4_hours','next_time') is none }}

Simple as that then :roll_eyes:

Thanks.

1 Like