I’m working on an existing custom integration to implement an energy usage sensor for a plug. I know that I can use the sensor platform for KWh… However, I’m a little confused about how to go about doing it and was hoping for someone that could provide a push in the right direction.
The data is coming as an array of the total usage per hour for each day. I’m unsure what the best way to push this into a sensor would be to collect/update based on that is.
Basically, I’m getting the data as a json element per day with each element in the ‘data’ field being a sequential hour of the day starting at the timestamp listed (GMT midnight on a date).
{
"data": "[0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
"date_ts": 1636588800000
}
Which I can of course convert into anything to make it easier to send into a sensor. However, this data is actively updated. So, as energy is used during that hour, this data will become:
{
"data": "[0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
"date_ts": 1636588800000
}
and so on. throughout that hour. I could delay the collection by an hour (basically getting the data for up to an hour, or two ago) to make that changing value easier to handle/less of an issue. However, I’m having a hard time conceptualizing how to get that into a sensor for KWh to collect historical data.
The examples in the dev pages here for total amount seem like they would make the most sense… But I can’t seem to find any examples of how that would actually work in code to insert data similar to the table for the sensor. Would the sensor update the value throughout the hour during the updated poll then write out the total during the next hour? Do I pass in the timestamp with value?
Thanks in advance for any insight.