Limych
(Andrey "Limych" Khrolenok)
February 26, 2019, 10:11am
1
Help me please!
Does any way to set value of template sensor to “undefined” state?
I’ve try it to set like this, but it’s not work
- platform: template
sensors:
owm_pressure_mmhg:
entity_id: sensor.owm_pressure
unit_of_measurement: 'mmHg'
friendly_name: "OWM Pressure"
value_template: >
{% if states.sensor.owm_pressure %}
{{ (states('sensor.owm_pressure') | float / 1.33322) | round(0) }}
{% endif %}
petro
(Petro)
February 26, 2019, 12:48pm
2
I can’t tell if you want it to set it to undefined or not…
- platform: template
sensors:
owm_pressure_mmhg:
entity_id: sensor.owm_pressure
unit_of_measurement: 'mmHg'
friendly_name: "OWM Pressure"
value_template: >
{% if states.sensor.owm_pressure.state is defined %}
{{ (states('sensor.owm_pressure') | float / 1.33322) | round(0) }}
{% else %}
0
{% endif %}
This template will never have ‘undefined’. But you’ll get 0 spikes on startups.
Limych
(Andrey "Limych" Khrolenok)
February 26, 2019, 12:59pm
3
Thank you for trying to help, but it’s not solution.
I’ve already have zero values of that sensor for undefined states of initial sensor.
I need to have undefined values.
petro
(Petro)
February 26, 2019, 1:00pm
4
Ok then, try this
- platform: template
sensors:
owm_pressure_mmhg:
entity_id: sensor.owm_pressure
unit_of_measurement: 'mmHg'
friendly_name: "OWM Pressure"
value_template: >
{% if states.sensor.owm_pressure.state is defined %}
{{ (states('sensor.owm_pressure') | float / 1.33322) | round(0) }}
{% else %}
undefined
{% endif %}
Just a question, why do you need to have undefined values?
Limych
(Andrey "Limych" Khrolenok)
February 26, 2019, 1:05pm
5
For correct drawing of graphs:
1 Like
petro
(Petro)
February 26, 2019, 1:06pm
6
Ah ok, give the new template a whirl. If that doesn’t work, we may need to try other values in that spot like None
.
Limych
(Andrey "Limych" Khrolenok)
February 26, 2019, 1:41pm
7
I’ve looked in the sensor code: alas, at the now there is no way to set an undefined value.
Thank you for trying to help…
petro
(Petro)
February 26, 2019, 1:43pm
8
You can use the first template in conjunction with the filter component to remove fliers. I.E. the zeros.
use the outlier filter. Then only track the filter sensor.
alder
January 9, 2020, 5:09pm
9
I had the same problem and found 2 solutions:
- platform: template
sensors:
owm_pressure_mmhg:
entity_id: sensor.owm_pressure
unit_of_measurement: 'mmHg'
friendly_name: "OWM Pressure"
value_template: >
{% if is_state('sensor.owm_pressure', 'unknown') %}
{{ states('sensor.owm_pressure') }}
{% else %}
{{ (states('sensor.owm_pressure') | float / 1.33322) | round(0) }}
{% endif %}
device_class: pressure
and
- platform: template
sensors:
owm_pressure_mmhg:
entity_id: sensor.owm_pressure
unit_of_measurement: 'mmHg'
friendly_name: "OWM Pressure"
value_template: "{{ (states('sensor.owm_pressure') | float / 1.33322) | round(0) }}"
availability_template: "{{ not is_state('sensor.owm_pressure', 'unknown') }}"
device_class: pressure
Limych
(Andrey "Limych" Khrolenok)
January 9, 2020, 8:47pm
10
When I opened this topic, there was no availability_template field in the sensor.
Subsequently, I initiated its addition to the sensor (though my version of the logic of this field turned out to be worse than the version from another participant).
alder
January 10, 2020, 8:45am
11
I’m also added device_class and example without availability_template. I just left a solution for people like me who will find this question but without a solution
You can mark this post as solved (if you agree with my solutions).