Hi all, I hope someone can help with this as I am so close…
I have a template sensor that is triggered using numeric_state platform of another sensor. This seems to be working fine and I can see when it is triggered using the logbook.
I am using influxdb to report the history of this sensor and this is also working.
The issue is that influxdb reports an event whenever HA starts but I am not seeing the event in the logbook so I don’t know how to stop this from happening.
Viewing the data from this sensor in influxdb or grafana. Every time I restart HA I think each sensor reports its state into influxdb creating ‘phamtom’ events.
I am looking at the the influx integration issues and I think this is an issue with influxdb not my HA config…
Below is the template sensor. This is working correcly.
And below is a table/report using grafana (connected to influxdb). The entries are mainly from me restarting HA as I have been trying to work out what is going on…
Oh ok. Pretty sure you can’t do anything about that.
The influxDB integration sends values to to the InfluxDB database whenever the state value changes. Nothing you can do about that, it’s the way the integration works.
Whenever Home Assistant restarts all entity states are set to unknown until their integration is loaded and the state value is restored. Nothing you can do about that either, it’s the way Home Assistant works.
So after a restart your sensor changes from unknown to some value and this change is reported to InluxDB.
You could probably filter out 0 values in your Grafana query.
Will only trigger when the sensor changes from below 0.1 to above 0.1. For example if you want it to trigger when changing from 10 to 20 this will not occur.
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: