History Services integration for exporting historical data

Hello Home Assistant community,

I couldn’t find any pretty solution when I was looking for some ways how to get from HA historical data of sensors in any shape or a form without directly working with the SQL database. And also found out that I’m not the only one who would appreciate such feature.

So I created this really small pseudo integration which should help anybody who wants to export basically any historical data of any sensor and does not want to play with the SQL. Integration exposes its functionality through the services.

Registered are two services. First one is really simple and just returns simple dump of a sensor’s history. Then there is the other, more extended service, which aims at ‘device_tracker’ entities and its output is already in KML format.

It’s still in very early stage of any development so whoever decide to give it a try should also expect bugs.

Feel free to suggest any enhancements, etc. as current state of the concept is very basic and thus limited in features.

Also… I’m mainly C# guy and touching Python only when I have to. So please excuse my c*appy code as I’m sure it’s bad. :smiley:

davidrapan/ha-history (github.com)

1 Like

This is a great idea, thanks for sharing it!

I’ll follow your integration closely.

1 Like

Hey there, so the integration is now in pretty usable state so i thought I can also post here some example how it can be used with automations :wink::

alias: Autoexport travel logbook
description: "Device: ???????"
  - platform: state
      - device_tracker.name_of_your_entity
    to: home
      hours: 1
      minutes: 0
      seconds: 0
condition: []
  - sequence:
      - service: history_services.export_device_tracker
          max_gap: 300
          min_radius: 100
          entity_id: "{{ trigger.entity_id }}"
          filename: "{{ trigger.entity_id }}"
          last_hours: 12
        response_variable: kml
      - service: system_log.write
        metadata: {}
          level: info
          message: "{{ kml['result'] }}"
mode: single

Replace name_of_your_entity with some existing one and then you can continue in the sequence and use the kml variable (Use is demonstrated using system_log.write), it’s a dictionary and KML is in kml['result'], or alternatively pick up the location data through stored file.

Have fun.