Integrate with Home assistant #53
Pinned
toggm
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Integrate with Home Assistant
With the following steps you can push the pv production data from your home assistant instance to a sun-set-analytics instance.
1. Install and start sun-set-analytics docker image
Install sun-set-analytics based on the description in the Readme
2. Provide a shell command to extract statistics data
The following shell script exports the pv production statistics data from the home assistant database. Place it somewhere in the home assistants
configurationdirectory:Be aware that:
apkpackage manage, therefore expects a debian based OS. The installation is executed within the shell script to ensure the tools exist. If you're running the script within a docker image, the installation is need every time after restarting the docker image.sensor.energy_producedwith the entity_id of the entity measuring the pv production, if not the sameThe reference the script from within a shell_command configuration:
Adjust the path to the script accordingly.
3. Define REST commands
Define the following REST commands to be able to communicate with the sun-set-analytics instance:
Replace
$SUN_SET_ANALYTICS_HOSTwith the url through which the application is reachable and$INSTALLATION_IDwith the id of the pv installation (defaults to 1).Create an API-Key and add the key with the
sun_set_analytics_api_tokenname to the home assistantssecrets.yamlfile.4. Create a script
Create a script to combine all steps:
The script calls the export shell_command, deletes all pv production data for the exported range and re-imports the data.
5. Schedule export job
In the end, setup a scheduled job (i.e. with an automation) to regularly (daily) run the previously defined script.
Manually import long term data
Home assistant doesn't allow to import long term data this way as a script can only receive a very limited number of bytes as data. If you want to import a longer period of data, you'll have to trigger the import manually by:
/config/configurations/shell_commands/export_energy_produced.sh "6 years" > /tmp/export.json(Execute the script within the docker image or adjust the path to the homeassistant_v2.db databaseha-pi:/config# cat /tmp/export.json | jq '{from: .from, to: .to}' { "from": "2022-02-11T20:00:00Z", "to": "2025-04-16T17:59:59Z" }curl -v -H 'Authorization: users API-Key $API_KEY' -X POST "$SUN_SET_ANALYTICS_HOST/api/installations/$INSTALLATION_ID/delete-production-data?from=$FROM_DATE&to=$TO_DATE", replace$SUN_SET_ANALYTICS_HOST,$API_KEY,$INSTALLATION_ID,FROM_DATEand$TO_DATEcurl -v -H 'Authorization: users API-Key $API_KEY' -X POST "$SUN_SET_ANALYTICS_HOST/api/installations/$INSTALLATION_ID/import-production-data" --data @/tmp/export.json, replace$SUN_SET_ANALYTICS_HOST,$API_KEYand$INSTALLATION_IDBeta Was this translation helpful? Give feedback.
All reactions