RE influxdb - makes sense. I will need to find a way to filter out the data created at startup in my grafana report. That should be possible I think…
Thanks for spotting the issue with my trigger. This setup is all new so not properly tested yet. I need this to fire all the time when the state is above 0.1. Can you help with this?
I see what you mean with the numeric state trigger now I have read about threshold.
What about this as a solution (as i think it could also help with the grafana report).
If I have an automation that resets the state of this sensor to 0 each time it is triggered. Then it would be ready for the next event and should always have a state of 0 at HA restart. Then I just filter all of the 0 state data from my report?
It seems like a clumsy and inefficient way of fixing this. What would you do?
Also the availability template means you don’t have to define default values for your float filters (except in the trigger). So you can just use |float instead of |float(0)
Legend. Thanks so much for all this input @tom_l. I will try this and see how it works.
This project is so close now. I have gps data from a phone. Calculate speed. Cleans crap data by calculating acceleration between data points. Pushes the clean data into traccar. Tracar works out speedlimit and pushes the data back into HA. Influx holds only the data where there was a ‘speeding’ event.
As triggered template sensors have their value restored after a restart, so you will still get the unknown → value issue after a restart causing the influx integration to log the value.
You will likely still need to filter this in Grafana.
No that won’t prevent the state going unknown after a restart. All entities go unknown after a restart until they are restored. This is because Home Assistant has no idea what happened while it was off so cannot assume any state values stayed the same.
Would it be worth trying an automation that stopped the influxdb addon before shutdown and restarting it after HA fully starts and has loaded all the states? So using hassio.addon_stop and hassio.addon_start. No idea if this would work, but it sounds feasible.
That is a good suggestion. Thanks. I am running HA in a container so I don’t use addons. Can I take the same approach but disable the influxdb integration?
Not sure that I can disable this integration as it is hard coded in confuration.yaml
Oh right. I thought it was always reporting 0 at start up. I see now that it would report whatever the value before restart was. You can do it like this:
Just a quick update on this now I have it all setup correctly (i think).
I am using 2 triggered entities. The first records speed but only when speed is over 40kmh (as i’m only interested in driving speed). The second is triggered by the first but only when the speed is 10% over the road speed limit. It is also triggered by HA shutdown.
I am expecting the second one to record an event whenever HA is restarted but I dont think this is happening as there are no logbook entries when I restart HA.
I wanted to update this thread in case it helps others with a similar challenge.
Turns out that using trigger.id in the state template was causing the issue. I don’t fully understand why but I think it is because the trigger.id is not set until after the state template is complete.
So what I did is to remove the if statement from the state template and added the trigger.id as a attribute. In grafana, I filter the report using the trigger.id to hide unwanted data created in influxdb/grafana when HA starts.
Here is the (finally) working results. Chart shows speedlimit and speed. Table embedded from grafana shows a list of speeding events (speed > 10% above limit).
Massive thanks to @tom_l and others for your help.
If you want it to record only at start up then you want the second trigger (trigger.id == 1), it starts counting at 0. So id 0 = 1st trigger, id 1 = 2nd trigger.