jcallaghan / home-assistant-config

My Home Assistant configuration & documentation.
https://www.jcallaghan.com/
MIT License
175 stars 8 forks source link

Upgrade available for Home Assistant version sensor and DevOps automation šŸ› šŸ˜ŽšŸš€ #105

Open jcallaghan opened 4 years ago

jcallaghan commented 4 years ago

Home Assistant upgrades rock and there is nothing nicer than upgrading to a fresh new release and getting access to all the updates. Inspired by Carlo I decided to track upgrades as an issue in GitHub.

To help you track when there is a new there are two integrations you can make use off the Updater integration which provides a binary_sensor. This also has attributes that provide more information about the new update. Then there is the Version integration integration that creates a number of sensors based on how you configure the integration. I've always found the version integration to be more responsive at alerting me about a new release.

With help from the above integrations, I've created a #DevOps process (similar to #103) to help me automate my upgrades. When a new release is available an automation is triggered. This creates a notification within Home Assistant and creates a new issue in GitHub. I use the rest_command integration with the GitHub APIs to create, comment and close issues. The issue that is created in GitHub allows me to track any issues or feedback about the release and also acts as a reminder that I need to perform an upgrade. To help me track if an issue has been created I use the rest sensor to find if there is an open issue in GitHub relating to upgrading Home Assistant. This helps me avoid creating duplicate issues when an update is available and is used to help me close the issue automatically. Once the upgrade has completed I automatically comment on the issue and close it.

Features

CCOSTAN commented 4 years ago

How is this different from https://github.com/CCOSTAN/Home-AssistantConfig/issues/606

jcallaghan commented 4 years ago

@CCOSTAN it isn't more of a companion.

I've never built out an automation to notify me of build updates. #103 was focused more on generic issue and battery. I might even leverage a script in front of the rest_command to add conditions so I can better handle labels etc. In terms of the Updater integration. This is perfect but with the addition of the Version integration, I can report on the current version and then use this in templates and things such as create a GitHub and tracking the version the issue was reported in.

jcallaghan commented 4 years ago

Lovelace

image

image

PS. I really need to sort out why I get "No history state found" on some of my entities. It feels like this has started since I migrated over to MariaDB #11.

jcallaghan commented 4 years ago

@CCOSTAN fun fact. The version sensor also seems to report more quickly than the updater.

image

jcallaghan commented 4 years ago

Automation to close GitHub issue after upgrade

To much surprise after some tinkering, I managed to build something that will close the GitHub issue raise when a new version is available when Home Assistant has upgraded to this version. This leverages the rest integration and rest command integration. The jsonpaths were a little tricky but I got there in the end and JSONPAth Online Evaluator was a real help. Sadly the rest_command isn't able to provide any response data from a success or error. This could have been used to get the GitHub issue number. Instead, I've achieved this with two automations and some helpers.

While it was fun. Due to the limitations, I experienced with filtering in jsonpath I'm not sure this can be used reliably due to the jsonpath not being specific enough.

I think was similar to what Jeff thejeffreystone/home-assistant-configuration#61 was looking for

Process

  1. When an update is released the binary_sensor.updater turns on triggering an automation.
  2. This sends a notification and calls my rest_command.github_new_issue_upgrade service which creates a new GitHub issue.
  3. I then have a rest sensor that queries GitHub for the latest issue number with some soft matches to help me home in on the issue created for the most recent upgrade.
  4. Then when the binary_sensor.updater turns off after an upgrade, a second automation is triggered.
  5. This replaces my persistent notification and calls a second rest_command service rest_command.github_close_issue.
  6. This rest_command is passed the issue number and posts an update to change the GitHub issue to closed.
  7. The rest sensors update with the new GitHub issue number within 20 seconds or so.

Todo

I need to look at the triggers as I don't think the upgrade completed automation is getting triggered. Additionally, I need to change the close process as it is changing the issuing body rather than adding a comment like intended.

GitHub issue numbers via Rest

These are the two rest sensors I've created to provide me with the most recent issue number and the issue number where there is a match for my upgrade issue.

image

image

References

jcallaghan commented 4 years ago

Updater

I've noticed that updater doesn't update automatically at all, while version does. Update 0.111.4 came through yesterday and the version latest sensor updated while updater still shows no update.

image

image

jcallaghan commented 4 years ago

Lovelace card with my helpers

image

jcallaghan commented 4 years ago

Rest sensor json wildcard search

https://github.com/jcallaghan/home-assistant-config/blob/master/entities/sensors/github/github_upgrade_issue_data.yaml

CCOSTAN commented 4 years ago

Version number as a Label would be pretty slick. Then you could extend that framework out to integrations etc..

jcallaghan commented 4 years ago

There is a label API so could easily be added as an action to the upgrade available automation. https://developer.github.com/v3/issues/labels/#create-a-label

Expand on this a little @CCOSTAN. As in I added integration x with version x? Or I had an issue with version x?

jcallaghan commented 4 years ago

https://developer.github.com/v3/issues/comments/#create-an-issue-comment

GitHub Developer
Issue Comments
Get started with one of our guides, or jump straight into the API documentation.
jcallaghan commented 4 years ago

https://developer.github.com/v3/issues/labels/#create-a-label

GitHub Developer
Issue Labels
Get started with one of our guides, or jump straight into the API documentation.