Allow blueprint upgrades

was working for me as well, but after i updated HA it gave an error about being malformed…

and there is not really a need for it since i can just put it back in after downloading if it isn’t there

Everything seems to work perfect.
I would suggest that since many people, like I do, have the folder scripts holding split configurations of HA scripts, another name be used for the folder as your suggestion. I have changed my folder name to scriptshell. This is only a suggestion and you can take it or leave it.
This is awesome in another way. I provide my blueprints formatted so that they are easier to read with the human eye. HA parses and checks it and pastes it like the machine likes to see it, so the templates and stuff gets mashed and hard to read by looking at it.
This actually fixes that…

The readme file is VERY nice as well…

I have a friend that has put together a few HA addons, perhaps this would be a bit smoother functioning and provide better HA interface in an addon form. Or perhaps find a way to meld this into HA core and become part of the core functionality. As you mentioned getting output, the ability to easily schedule this and notify users that an update is available would be the next steps. It really is a big help just like this, however.

13 blueprints updated in about 7 seconds…

In regards to source_url, it was my understanding that that value was inserted on blueprint import, so I removed it from the HASPone blueprints as it didn’t seem to matter (and wasn’t mentioned in the examples). I have no personal opinions about this one way or the other, so if it makes more sense to put those values back, I can get that done right away.

Are you not seeing that value populated on import?

The carpresence ones didn’t have source_url (originally) in the repo, but I had added it in my personal imported copy, When this script came about, I added custom- (for the early versions) and it was able to check for new revisions.

Originally with this script if it wasn’t in the master, and you did not have custom- added to it, it would import via this script without the source line, but rather an exact copy of the master.

Now I think the script behavior has changed, but I think it’s a good idea for the line to be there as then the exact copy in the master will import into the user’s folder.

I don’t have any HASPone but I assumed they didn’t have that line either.

The /config/scripts/ dir is not hard-coded anywhere, you can put the script anywhere you’d like to put it, also when updating it updates the filename which was called as the command.

I guess i should mention in the readme file that the /config/scripts/ dir is just an example.

I’ll look into giving the script a bit better structure, which should help in being able to update just one blueprint, instead off all-or-nothing. I don’t have any experience with writing addons, but maybe i’ll look into that. Help on that part is always welcome, but i guess that we should start a proper github repo for that, since gists are quite limited in functionality.

More than one code block in the top message.

do you have a link for that one? so i can see if i can at least detect it so the script doesn’t break a working yaml by extracting the wrong content.

I wouldn’t worry about it because it can’t exactly import with HA either.
It occurs when the original post is the source of the blueprint code, and the same top post also has a second code block. HA will not import this because it does not know which code block to use, I assume. (I can’t find one now because it is a known problem and people tend to fix it right away)

The one that would not import for me turned out to be a bad url. The url went to the correct series of posts BUT it also had a /10 at the end indicating post number. Only the code block in the top post number is available for importing.

These are both edge cases that I would not worry about, as neither would have actually imported using HA anyway.

I added a comment in the gist, couple of questions…

Just stumbled across this and thought I’d give it a try. Worked fine a couple of times this morning but I get this this afternoon,

> ./blueprints_update.sh
-> self up-2-date

> ./automation/SirGoodenough/Zigbee2MQTT-Xiaomi_Cube_Controller_MQTT_Triggered.yaml
-> source_url: https://github.com/SirGoodenough/HA_Blueprints/blob/9784177ef3550f395b39fcfe0c88644c09e12a48/Automations/Zigbee2MQTT-Xiaomi_Cube_Controller_MQTT_Triggered.yaml
-! fix github url to raw
-> fixed source_url: https://raw.githubusercontent.com/SirGoodenough/HA_Blueprints/master/Automations/Zigbee2MQTT-Xiaomi_Cube_Controller_MQTT_Triggered.yaml
-> download blueprint
-> compare blueprints
-> blueprint up-2-date

> ./automation/cvroque/webostv_turn_on.yaml
-> source_url:           <td id="file-webostv_turn_on-yaml-LC29" class="blob-code blob-code-inner js-file-line">  <span class="pl-ent">source_url</span>: <span class="pl-s">https://gist.github.com/cvroque/6780ca0869ef781e9de3b506fd501f78#file-webostv_turn_on-yaml</span></td>
-! fix github gist url to raw
-> fixed source_url:           <td id="file-webostv_turn_on-yaml-LC29" class="blob-code blob-code-inner js-file-line">  <span class="pl-ent">source_url</span>: <span class="pl-s">https://gist.githubusercontent.com/cvroque/6780ca0869ef781e9de3b506fd501f78#file-webostv_turn_on-yaml</span></td>/raw/webostv_turn_on.yaml
-> download blueprint
-! something went wrong while downloading, exiting...

Running this from terminal with the --debug switch. Not sure if this helps you?

Chris

Also, I’m now getting this error when I open Studio Code Server,

'blueprints/automation/cvroque/webostv_turn_on.yaml' could not be parsed, it was referenced from path 'blueprints/automation/cvroque/webostv_turn_on.yaml'.This file will be ignored. Error(s): - YAMLSyntaxError: All collection items must start at the same column - YAMLSemanticError: Implicit map keys need to be on a single line - YAMLSemanticError: Nested mappings are not allowed in compact mappings - - And 250 more errors...

Very confused now.

EDIT: replaced the webostv_turn_on.yaml with a backup and the above error goes away. The file I overwrote is significantly different from the backup.

I suppose I’m hinting/guessing that the upgrade script changed my file? On the other hand, there are many trees here I can bark up!!!

What it tries to overwrite your loaded file is an exact copy of what is currently in the URL. I have tested my blueprints to work properly with this script. If the source URL is bad of if there is a problem with the name formatting and possibly other untested edge cases, it will not work.
I suggest having a back-up copy of your blueprints before you try this, or try it in test mode to see what is going to happen first.

I need to do a bit more testing as this did work the first few times I ran it, but a couple of hours later, with no change in blueprints, I got errors and spotted the overwritten file.

Test mode – Ahha!

thanks @Sir_Goodenough for handling the replies on the thread :smiley:
i’m not very active on the forum/community, so i don’t notice the updates that quick…

i’ll look into moving the script into a github repo, and try to fix some of the issues mentioned in this thread

1 Like

the URL in the blueprint is LG webOS Smart TV - Turn On · GitHub which points to a webpage which shows a yaml file…
the actual source url should be https://gist.github.com/cvroque/6780ca0869ef781e9de3b506fd501f78/raw/webostv_turn_on.yaml

my script did sort of check for this, but did not take into consideration the edge-case where the #file-webostv_turn_on-yaml was at the end of the url

1 Like

i have made a full github repository for this script, which you can find on GitHub - koter84/HomeAssistant_Blueprints_Update: This is a script to automatically check for updates for your HA Blueprints

i’m currently fixing some errors and adding a couple of features, once i commit that to the new repository i’ll update the gist script to auto-update to the new repository.

I noticed you are pulling the source from the gist here, not the git repo…

mkdir -p /config/scripts/
cd /config/scripts/
wget -O blueprints_update.sh https://gist.githubusercontent.com/koter84/86790850aa63354bda56d041de31dc70/raw/blueprints_update.sh
chmod +x blueprints_update.sh

That’s from the repo readme.md

UPDATE—>
Nevermind, I see your note above…

1 Like

@Sir_Goodenough you are very quick…

the updated version is now live on gist and github, with the gist pointing to the github version as well, so at least until the next update people shouldn’t have to double update just because of moving the location.

i added a .conf file so you can store a server-url and long-lived-token which are used to create and dismiss persistent notifications, it’s also possible to set auto-update to true in that .conf
the notification also shows the full update command for just that script, so it can be easily copy-pasted to the terminal
when auto-update is true the script generates a persistent notification when the script is updated, and won’t automatically dismiss it

unfortunately i haven’t found a way to make the persistent notifications actionable, but i have also not found a way to actually give commands to the script…

i added a --file option, so you can just process a single file, and a --file self option to just update the script itself.

when run in --debug mode the script shows a diff between the old and new version

i fixed the error with the empty source_url field getting saved, i forgot to change a variable after removing the custom- thingy (which gave a syntax error in HA)
after actually saving the source_url i hit another problem, with the community-hosted blueprints which would get a .json.json ending, which didn’t work, but i fixed that as wel…

please do test, and let me know how it goes, when anyone bumps into an issue please add a link to the blueprint you are trying to use!

@koter84 Thanks for the info, I’ve not gone back to look, been too distracted with life events. Normal service next week I hope.

I am building a new blueprint right now, so I will test it later this evening. Thanks for the work, looks good so far!

Update
Tried the --debug and the --file option to check and update a single BP. (1500 line BP that is…)
Would need more info on how to use/test the .conf file and the notifications.
I then updated everything else in 1 shot.

Looking good so far.

Tomorrow thinking about downloading a stack of random BP’s and see if they process correctly.