I created a sensor for hvac_action in hopes that I can graph the run time of heating with the temperature of the room temp sensor in the same graph. I wanted it to look like the graph for climate.thermostat which has thermostat heating and thermostat target temp high and thermostat target temp low and thermostat current temp all as line graph data.
When I graph sensor.hvac_action I get a graph that doesn’t changes levels, only colors for the state, even if I add sensor.room_temp which causes them to be two different graphs within the same graph card.
What do I need to do to in order for heating from sensor.hvac_action to be a line graph?
I figured out why the sensor.hvac_action graph looks like it does. At https://www.home-assistant.io/lovelace/history-graph/ it has an example which looks the same and states it shows as it does since the sensor has no unit_of_measurement defined
I still have no idea how to get that into a defined unit of measurement. Should this be a solution? I would like the time to be accurate to the minute.
- platform: history_stats
name: Heating On
entity_id: sensor.hvac_action
state: 'heating'
type: time
start: '{{ 0 }}'
end: '{{ now() }}'
Hi - I’m not clear on what you are specifically trying to graph. If it is the cumulative on-time for the day, then the units would be seconds (or minutes or hours - depends on how you do the calculation). Can you let me know what it is you are trying to graph? In my config, I use the history_stats platform to create a sensor called sensor.boiler_on_time_today to total up how many hours my HVAC is on each day - it’s like this:
- platform: history_stats
name: Boiler On Time Today
entity_id: binary_sensor.boiler_on
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
The binary_sensor.boiler_on is based on the thermostat-created sensor sensor.dining_room_thermostat_hvac_state (I included the A/C units, too, for completeness):
To answer this one, it seems history_stats based on time has a unit of hour. I didn’t do anything special in my previous post of the graph. It’s as simple as this in lovelace:
I added that to my sensors.yaml and restarted. I now have sensor.binary_heating_on under States in Developer Tools and I was able to graph that.
However I was looking more for a graph with a data point for each second it is on and no data point for each second it is off as opposed to what we get now with our setups where there is a data point regardless if it is off or on.
Is there a way to make ‘on’ the number 100 and ‘off’ the number 0 and that way there is a defined unit_of_measurement for HVAC Heating?
Yes - the template sensor replaces the history_stats sensor. If you want to graph it with your other temperatures, you might want to make the of measurement °F or °C, depending on what you are using. Otherwise, they will end up on two different graphs, at least that’s been my experience.
Here’s my edit (for completeness) which is very much like @JTPublic’s:
I have friendly_name: “HVAC Heating” as the binary_sensor.hvac_heating. Does the fact that it is no longer going to be binary cause it to be a regular sensor? Can I do as KSC suggested and use unit_of_measurement: ‘°F’ instead? If so, does that eliminate the need for the template sensor that converts to ‘°F’ ?
Yes, it is now a regular sensor, not binary_sensor anymore, any numeric unit_of_measurement will work. You need such unit_of_measurement to tell history-graph to plot the entity as numeric line.
I was able to use your solution to create one for heating and one for cooling for the days like today where the outside low temp in the morning created the need for heating and the outside high temp in the afternoon created the need for cooling. So now the graph has them as different colored lines.
Another improvement that can be made is to get the exact temperature set value from the thermostat by replacing “72” with {{states.climate.thermostat.attributes.temperature}}