some of us have a thing about units, data and graphs
The Home Assistant sensor graph offers painless autoscaling with options to set detail and timespan. But how do I alter the data itself?
A car fuel tank measures in gallons but it’s more useful to know how many miles we can travel or how much fuel the tank needs to fill up. When collecting data, sometimes you want to change say, a Watt value into kW or a cost in $ or £. When my oil tank sensor gives me a distance (cm) I need to turn that into a volume of oil (in litres/gallons).
I’m getting ahead of my skills but mention this now to remind that useful calculations are possible. Some sensor calculations and adjustments are easier to code than others. The wider community may even have shared their working. There are add-ons (I think Grafana is one) which do maths. Otherwise you must use the built-in Home Assistant template platform (and really finicky awful Jinga code) to do calculations.
Home Assistant’s filter platform (read here) applies maths functions to data – it calculates a moving average, or it throttles or removes outlying values. A low-pass filter smooths a graph’s peaks and valleys. The beauty of the trick is you take any sensor data and rework it, which in this case makes the graph line less ragged. For example:
# Use of a filter to select only some of the data measured sensor: - platform: filter name: "bathroom_humidity" entity_id: sensor.bathroom_humidity filters: - filter: lowpass time_constant: 10 precision: 2 # Can even use a template to choose a different sensor attribute - platform: template sensors: sun_angle: friendly_name: "sun elevation" unit_of_measurement: 'degrees' value_template: "{{ state_attr('sun.sun', 'elevation') }}" # see https://www.home-assistant.io/integrations/template/


smoothing a graph is like turning a sharp hi-res TV into a blurry old low-res TV
RF
