Paxy
(Paxy)
June 1, 2018, 7:47am
1
Hi folks,
Is it possible to access the state of the sensor in history db?
Something like sensor state yesterday, or one week ago, or even beginning of the month?
I see there is custom sensor component https://www.home-assistant.io/components/sensor.history_stats/ but this is not what I need.
Wish to use history state in sensor tamplate.
RobDYI
June 1, 2018, 10:29pm
2
You can use the api of HA to retrieve that info.
you could create a restful api sensor and parse the json for the info you need
try the url in your browser
http://localhost:8123/api/history/period/2018-5-31T00:00:00+02:00
https://developers.home-assistant.io/docs/en/external_api_rest.html
GET /api/history/period/
Returns an array of state changes in the past. Each object contains further details for the entities.
The (YYYY-MM-DDThh:mm:ssTZD) is optional and defaults to 1 day before the time of the request. It determines the beginning of the period.
You can pass the following optional GET parameters:
filter_entity_id=<entity_id> to filter on a single entity
end_time= to choose the end of the period in URL encoded format (defaults to 1 day).
1 Like
akeslo
(Akeslo)
June 2, 2021, 2:14am
3
Is this still the best method?