Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95445

Don't push template change

$
0
0

@Valentino_Stillhardt wrote:

Hi everyone,

I’m writing a template_sensor which should fetch another sensor and do some basic calculations.

Basically I’m using:

  - platform: template
    sensors:
      all_3_phases_power:
        friendly_name: "All Phases Power"
        value_template: >-
          {% set phases = (states('sensor.phase_1_power') | float + states('sensor.phase_2_power') | float + states('sensor.phase_3_power') | float) | round(2) %}
          {% set phase_1_updated = (now().timestamp() - states.sensor.phase_1_power.last_changed.timestamp()) < 1 %}
          {% set phase_2_updated = (now().timestamp() - states.sensor.phase_2_power.last_changed.timestamp()) < 1 %}
          {% set phase_3_updated = (now().timestamp() - states.sensor.phase_3_power.last_changed.timestamp()) < 1 %}
          {% set all_phases_updated = phase_1_updated and phase_2_updated and phase_3_updated %}
          
          {% if phases != 'unavailable' and phases > 0.0 %}
          {% if all_phases_updated %}
          {{ phases | float | round(2) }}
          {% endif %}
          {% else %}
          {{ 'unavailable' }}
          {% endif %}
        unit_of_measurement: "W"
        icon_template: mdi:power

The problem is if all_phases_updated is False, the sensor gets an empty value, and I just want it to stay at the last value (Not pushing the value).

The reason I need to push if all_phases_updated is True is because it updates 3 times in rapid sucession to every update in the 3 phases (every 5s), so I watch first if all 3 phases have updated in the last 1 sec and only then push the value to the template.

So, the question is: How do I avoid a empty value in the template when the value isn’t “ready” (aka. How do I not push a value to the template/ignore this iteration)?

Thanks in advance

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>