jmoneo
(Joaquin)
July 31, 2019, 10:49am
1
Hi,
I have a dark sky sensor which is malfunctioning:
I would like to make a custom sensor that takes the dark sky data, but hides the “0” values. This is what I have by now:
Hoy_Tmax:
friendly_name: "Hoy Tmax"
unit_of_measurement: 'degrees'
value_template: "{{ states('sensor.dark_sky_daytime_high_temperature_0d') }}"
Is there any function for the template to skip the “0” and retain the last correct value?
Thank you very much.
tom_l
July 31, 2019, 10:52am
2
Use the outlier filter sensor:
A radius of 10 should do it.
sensor:
- platform: filter
name: "Filtered Hoy Tmax"
entity_id: sensor.dark_sky_daytime_high_temperature_0d
filters:
- filter: outlier
window_size: 4
radius: 10
If the current value differs by 10 from the mean of the last three readings it will be discarded.
1 Like
jmoneo
(Joaquin)
August 1, 2019, 9:16am
3
The problem is that it is not one good value, one “0” value.
It can be “0, 0, 28, 0, 28, 0, 0, 0, 28”, so the mean won’t be right.
It would be a great idea if it was regular, but it looks like it is not working:
Isn’t there any other way to hide the zeros?
tom_l
August 1, 2019, 9:28am
4
Ok try this template sensor:
- platform: template:
sensors:
name: "Filtered Hoy Tmax"
entity_id: sensor.dark_sky_daytime_high_temperature_0d
value_template: >
{% if states('sensor.dark_sky_daytime_high_temperature_0d') | float == 0 %}
{{ states('sensor.filtered_hoy_tmax') }}
{% else %}
{{ states('sensor.dark_sky_daytime_high_temperature_0d') }}
2 Likes
petro
(Petro)
August 1, 2019, 12:16pm
5
If you never get close to zero use the range filter instead of the outlier filter.
- platform: filter
name: "Filtered Hoy Tmax"
entity_id: sensor.dark_sky_daytime_high_temperature_0d
filters:
- filter: range
lower_bound: 1
Anything below 1 will be replaced with the last value.
2 Likes
jmoneo
(Joaquin)
August 1, 2019, 1:37pm
6
Tom’s one worked perfect.
Petro, in winter, in my city, temperature is lower 0 (celsius), so it wouldn’t work that well.
Thank you very much guys!
petro
(Petro)
August 1, 2019, 3:14pm
7
You may want to revisit your template then. If you can get below zero in the winter, then the temperature can also be zero. But that template will throw out those values.
Are you sure that the the high temperature gets set to zero when it disconnects? I would assume it get’s set to null or None.
jmoneo
(Joaquin)
August 2, 2019, 8:45am
8
I’m ok with skipping those 0 values. It won’t be that often as the temperature is given with decimals, which won’t be discarded.
It looks like it gets set to 0.
I have been experience same issue with my temperature sensor.
Those zeros should be coming from the default value of float() filter when it fails to convert the given state to float number.
Template Designer Documentation
You might override the default value with the first parameter.
- platform: template:
sensors:
name: "Filtered Hoy Tmax"
entity_id: sensor.dark_sky_daytime_high_temperature_0d
value_template: "{{ ( states('sensor.dark_sky_daytime_high_temperature_0d') | float( states('sensor.filtered_hoy_tmax') ) ) }}"
2 Likes
berzezo
(Berzezo)
May 27, 2020, 8:29pm
10
Based on the documentation not the last value but the upper or lower bound: