Graph of when automation was triggered

@MattMattMattMatt with this simple setup for a Lovelace Sensor card it only shows a value:

type: sensor
entity: sensor.my_automation
hours_to_show: 168

screenshot

If I include graph: line I get the following warning:

Entity: sensor.my_automation - Has no Unit of Measurement and therefore can not display a line graph.

I’m not sure what the unit_of_measurement (or just unit according to Sensor card docs) should be, can’t find a definitive list of them either.

Looking at the frontend code it literally is just a check for the unit of measurement. I’d put in:

unit_of_measurement: ' '

and just see if it works.

Yes, you need to add a unit of measure. Otherwise it assumes it’s a string.

Adding unit_of_measurement: ' ' doesn’t seem to change anything:

screenshot

You may need to assign a numerical unit_of_measurement, i.e. kwh or watts or something. Also, you most likely will have to purge your database.

Setting unit_of_measurement to kwh or watts doesn’t seem to change the graph.

In terms of purging database I’ve followed these instructions and waited a few days, not sure if that covers it? My graph still displays like this:

screenshot

Hi @Alec - it looks like your original state is ‘On’ rather than ‘on’.
Have you tried using an upper case O rather than the lower case o in the template sensor that @petro provided.

I have the same problem trying to report river levels. I have the values but am getting the bar graph. I’ve tried putting in the unit_of_measurement. Can someone please verify whether this goes into the lovelace file, or if it has to be an attribute of the entity being displayed? And can you verify the name is unit_of_measurement or unit_of_measure, or some other version of that phrase?

does your state include the units or are the units separate?

Thanks for the suggestion @chairstacker, I’ve tried that but no impact:

screenshot

Current Lovelace card config:

type: history-graph
title: My Automation
entities:
  - sensor.my_automation
hours_to_show: 168
refresh_interval: 0
unit_of_measurement: kwh

Sensor config:

- platform: template
  sensors:
    my_automation:
      value_template: "{{ 1 if is_state('automation.my_automation', 'On') else 0 }}"

Wouldn’t your value turn the result into a string due to the quotation marks around it.
Have you tried it without or with just single quotes?

That’s not working because your template has a capital O for on.

- platform: template
  sensors:
    my_automation:
      value_template: "{{ 1 if is_state('automation.my_automation', 'on') else 0 }}"

Also, you will need to purge your database because now it thinks it’s a string.

@chairstacker, it work because 1 or 0 are integers. The parser will attempt to convert to a number first.

If he adds a unit of measure, shuts off HA, clears database, and restarts HA, then it should show up as a graph. Assuming that automation.my_automation is the name of his automation.

Thanks @petro I have switched back to 'on'.

The unit_of_measurement in the Lovelace card config is set to kwh.

shuts off HA, clears database, and restarts HA

I’m using Hass.io, not sure how to do this? As mentioned above I’ve tried this which is all I could find on the topic.

I mean, if you don’t care about your history, just delete the file. That’s the easiest way. Sometimes purging the database doesn’t work with the service. And to be honest, you should probably delete the whole thing anyway because I’m not entirely sure if the item will be removed if you purge.

Thanks, I have deleted all home-assistant_v2.db files from /config and restarted which has cleared the history. Hopefully I’ll have a graph in a day or two, will report back!

screenshot

well, that’s already a problem. unknown will not change it to a numerical result. It should be showing a graph right now at zero.

can you post your automation and your template sensor? Possibly your entire config?

Also, I just realized you are putting the unit_of_measure on the wrong object. It should be attached to your sensor, not in the configuration for history-graph.

@petro thank you, I now have a line graph!

- platform: template
  sensors:
    my_automation:
      unit_of_measurement: 'kwh'
      value_template: "{{ 1 if is_state('automation.my_automation', 'on') else 0 }}"

screenshot

Looks like 1 is set each time HA restarts, when all automations get set to on which I assume is normal behaviour. These are the only values that appear on the graph.

Thing is, I don’t want to record on the graph each time the automation is switched on I want to record each time the automation is triggered.

1 Like

Hmm, if you want to record triggers, you may need to re-think this. Do you want this to record when it runs actions or triggers. Because conditions can stop it from running actions but the trigger will still occur.