History graph rendering as categories instead of continuous values

Hi all!
I’m trying to figure out why my history graph component is acting weird. I have some TP-LINK HS110 power monitoring plugs and I’m looking to display the current power as a line graph.

I used a template sensor to access the current_a attribute like so:

  - platform: template
  sensors:
    wills_bedside_current_a:
      friendly_name: "Wills Bedside"
      value_template: "{{ states.switch.wills_bedside.attributes.current_a | float}}"
    melis_bedside_current_a:
      friendly_name: "Wills Bedside"
      value_template: "{{ states.switch.melis_bedside.attributes.current_a | float}}"
    bedroom_litter_current_a:
      friendly_name: "Bedroom Litter"
      value_template: "{{ states.switch.bedroom_litter.attributes.current_a | float}}"
    livingroom_litter_current_a:
      friendly_name: "Livingroom Litter"
      value_template: "{{ states.switch.livingroom_litter.attributes.current_a | float}}"

and then I made a history graph like so:
wills_bedside_history:
entities:
- sensor.wills_bedside_current_a
- sensor.melis_bedside_current_a
- sensor.bedroom_litter_current_a
- sensor.livingroom_litter_current_a
hours_to_show: 8

I’m expecting a line graph (especially since I used the | float operator). But instead I get categorical plot.

Any thoughts on how to fix this?

I’m not sure of this, but I suspect that the values are being treated as strings instead of floats because of the quotes around the values, have you tried removing the quotes for the value_template? eg:

  - platform: template
  sensors:
    wills_bedside_current_a:
      friendly_name: "Wills Bedside"
      value_template: {{ states.switch.wills_bedside.attributes.current_a | float}}
    melis_bedside_current_a:
      friendly_name: "Wills Bedside"
      value_template: {{ states.switch.melis_bedside.attributes.current_a | float}}
    bedroom_litter_current_a:
      friendly_name: "Bedroom Litter"
      value_template: {{ states.switch.bedroom_litter.attributes.current_a | float}}
    livingroom_litter_current_a:
      friendly_name: "Livingroom Litter"
      value_template: {{ states.switch.livingroom_litter.attributes.current_a | float}}

Hmm. Removing the quotes leads to a parse error in the yaml-validation.

I tried using single quotes and that didn’t work … not that I expected a difference.

I noticed as I rebooted the hassio there are some Unknown values that snuck in during the restart. That seems to be hinted at in the Template sensor documentation. Maybe that’s why it is rendering things thinking they’re all strings. However, I can’t figure out how to purge just those values from the history without purging everything. Is there a way to do that?

Not sure how you can clear the history, sorry.

I think you need to add unit_of_measurement, here is someone who had the same problem.

2 Likes

Yup, that worked. I didn’t realize the unit_of_measurement defined which graph type would be displayed.

Thanks for the help!!