Pimatic and Homeduino Changelog and update notification
This is all about creating changelog and update devices for pimatic core and the homeduino plugin.
When you are ready it will look something like that :
For all of you that won’t read the stuff below and know what they are doing, here you can find the code for the several sections of your config.json (plugins, devices, variables, rules):
Pimatic update notification code
And don’t forget to install the github changes plugin npm install -g github-changes
For all the rest of you who want to wysiwyg i’ll explain the needed steps below. Let’s begin …
I suggest you stop Pimatic first to make all neccesary changes to the config.json.
1 Installing the needed software
Go to the bash and use the command sudo npm install -g github-changes
The program github-changes will be installed now. What it does? It fetches commit notifications from github repositories. Will be used later in rules.
2 Creating device for existing version on your pi / computer
Go to the device section of the config.json and paste the following devices :
{
"id": "pimatic-version",
"name": "Pimatic Version",
"class": "ShellSensor",
"attributeName": "version",
"attributeType": "string",
"command": "cat /usr/local/pimatic-app/node_modules/pimatic/package.json | grep version\\\": |awk {'print $2'}|sed 's/,//g' |sed 's/\"//g'",
"interval": 180000
},
{
"id": "homeduino-version",
"name": "homeduino Version",
"class": "ShellSensor",
"attributeName": "version",
"attributeType": "string",
"command": "cat /home/pi/pimatic-app/node_modules/pimatic-homeduino/package.json |grep version\\\": |awk {'print $2'}|sed 's/,//g' |sed 's/\"//g'",
"interval": 180000
}
Will look like that
and
3 Device for getting the actual online version
Again paste these devices to the devices section of your config.json
They will check the actual version on github. For that the package.json will be parsed.
{
"id": "pimatic-version-git",
"name": "Pimatic Version Request",
"class": "ShellSensor",
"attributeName": "versionrequest",
"attributeType": "string",
"command": "curl -s https://github.com/pimatic/pimatic/blob/master/package.json | grep version | grep span | awk -F\\> {'print $11'} | awk -F\\< {'print $1'}\n",
"interval": 21600000
},
{
"id": "homeduino-version-git",
"name": "homeduino Version Request",
"class": "ShellSensor",
"attributeName": "versionrequest",
"attributeType": "string",
"command": "curl -s https://github.com/pimatic/pimatic-homeduino/blob/v0.9.x/package.json | grep version | grep span | awk -F\\> {'print $11'} | awk -F\\< {'print $1'}\n",
"interval": 21600000
}
4 Creating the update info devices
The following devices will show if there is an update available or not.
{
"id": "pimatic-update-gui",
"name": "pimatic update info",
"class": "VariablesDevice",
"variables": [
{
"name": "pimatic-update-gui",
"type": "string",
"expression": "$pimatic-update-info"
}
]
},
{
"id": "homeduino-update-gui",
"name": "homeduino update info",
"class": "VariablesDevice",
"variables": [
{
"name": "homeduino-update-gui",
"type": "string",
"expression": "$homeduino-update-info"
}
]
}
Will look like that
and
The info will change when there is an update - you will see later when creating then neccesary rules
5 Creating the iframe devices as containers for the changelog text
As you are still in the devices section, continue with pasting the following devices for showing the changelog text.
Make sure to change the password and the ip adress as well as the path to the changelog file that will be neeeded and explained later.
The below path is the standard path to the home directory of the pi. Therefore usually you only need to insert pwd and ip. The logfile will be created automatically by rule.
{
"class": "iframeDevice",
"id": "homeduino-changelog",
"name": "Homeduino Changelog",
"url": "http://admin:password@YOUR-PIMATIC-IP-HERE/files/home/pi/homeduino-changelog.log",
"width": 600,
"height": 150,
"border": 0,
"scrolling": "yes",
"scale": 1,
"reload": 30
},
{
"class": "iframeDevice",
"id": "pimatic-changelog",
"name": "Pimatic Changelog",
"url": "http://admin:password@YOUR-PIMATIC-IP-HERE/files/home/pi/pimatic-changelog.log",
"width": 600,
"height": 150,
"border": 0,
"scrolling": "yes",
"scale": 1,
"reload": 30
}
Here you can see what you have done at that step when all is running
6 Creating variables for the update-gui variables device from step 4
Now go to the variables section of your config.json. You can search your config for the following string : "variables": [
since this will introduce the variables section.
Insert the following variables :
{
"name": "pimatic-update-info",
"value": "No update found"
},
{
"name": "homeduino-update-info",
"value": "No update found"
}
You can also do this step in pimatic’s variables menu. just create the variable there if you prefer that. See here for howto
7 Prepare the plugins
Still editing your config.json you will now copy and paste the following plugins (if not already exist!!)
The filebrowser is needed to read the logfile with the commits into the iframe containers from step 5
{
"plugin": "filebrowser",
"mappings": [
{
"path": "/files",
"directory": "/"
}
]
},
{
"plugin": "iframe"
},
{
"plugin": "shell-execute"
}
8 Prepare rules for getting commits and compare version numbers
The easiest way would be - since you are still editing your config.json - copy and paste the following rules completely to your rules section.
{
"id": "pimatic-update-available",
"name": "pimatic update available",
"rule": "if $pimatic-version-git.versionrequest is not $pimatic-version.version then set $pimatic-update-info = \"Update to v$pimatic-version-git.versionrequest available\"",
"active": true,
"logging": true
},
{
"id": "pimatic-update-not-available",
"name": "pimatic update not available",
"rule": "if $pimatic-version-git.versionrequest is $pimatic-version.version then set $pimatic-update-info = \"No update found\"",
"active": true,
"logging": true
},
{
"id": "pimatic-changelog-request",
"name": "pimatic changelog request",
"rule": "if $pimatic-version-git.versionrequest gets updated then execute \"sudo github-changes -o pimatic -r pimatic -f /home/pi/CHANGELOG-PIMATIC.md && head -23 /home/pi/CHANGELOG-PIMATIC.md | tail -20 | awk '-F)' \\{'print \\$2'\\} | sed 's/(//g' > /home/pi/pimatic-changelog.log\"",
"active": true,
"logging": true
},
{
"id": "homeduino-update-available",
"name": "homeduino update available",
"rule": "if $homeduino-version-git.versionrequest is not $homeduino-version.version then set $homeduino-update-info = \"Update to v$homeduino-version-git.versionrequest available\"",
"active": true,
"logging": true
},
{
"id": "homeduino-update-not-available",
"name": "homeduino update not available",
"rule": "if $homeduino-version-git.versionrequest is $homeduino-version.version then set $homeduino-update-info = \"No update found\"",
"active": true,
"logging": true
},
{
"id": "homeduino-changelog-request",
"name": "homeduino changelog request",
"rule": "if $homeduino-version-git.versionrequest gets updated then execute \"sudo github-changes -o pimatic -r pimatic-homeduino -b v0.9.x -f /home/pi/CHANGELOG-HOMEDUINO.md && head -23 /home/pi/CHANGELOG-HOMEDUINO.md | tail -20 | awk '-F)' \\{'print \\$2'\\} | sed 's/(//g' > /home/pi/homeduino-changelog.log\"",
"active": true,
"logging": true
}
These rules are neccesary for a flawless work of the changelog and update notification. Above you can see that there are two rules executing github-changes that you installed at the beginning (step 1).
You can create these rules at the pimatic rules menu, but be aware of the escaped characters since above is all json code and in the rules menu you are working online and don’t need to escape. Check here for howto
Well that’s all guys! No real problem i suggest, just some copy and paste work to do.
Now go ahead and start pimatic and see what happens
If you also want to have the nice system buttons device you see at the top (see 1st. picture upper left device) you can go ahead now :
9 Prepare buttons device
Now that you are skilled in copy and paste go to your devices section and copy the following device
{
"id": "systembuttons",
"name": "System Commands",
"class": "ButtonsDevice",
"buttons": [
{
"id": "button-reboot",
"text": "Reboot Pi"
},
{
"id": "button-shutdown",
"text": "Shutdown Pi"
},
{
"id": "button-pimatic-restart",
"text": "Restart pimatic"
},
{
"id": "button-homeduino-update",
"text": "Update Homeduino"
}
]
}
This will add the buttons device that will look like that :
10 Preparing rules for the system buttons
Now you need to create some rules to make the above buttons device work properly.
Copy the following rules to the rules section of your config.json. You may also create them at the rules menu. Have a look here
{
"id": "system-homeduino-update",
"name": "System Homeduino update",
"rule": "if button-homeduino-update is pressed then execute \"sudo bash /home/pi/homeduino-online-installer.sh\"",
"active": true,
"logging": true
},
{
"id": "system-pimatic-restart",
"name": "System Pimatic restart",
"rule": "if button-pimatic-restart is pressed then execute \"sudo service pimatic restart\"",
"active": true,
"logging": true
},
{
"id": "system-reboot",
"name": "System reboot",
"rule": "if button-reboot is pressed then execute \"sudo reboot\"",
"active": true,
"logging": true
},
{
"id": "system-shutdown",
"name": "System shutdown",
"rule": "if button-shutdown is pressed then execute \"sudo shutdown -h now\"",
"active": true,
"logging": true
}
11 Create a bash script for homeduino update
Last step is to create a bash script for updating homeduino from the gui. We’re working on a plugin that does this step automatically. Till then you may help you with this solution.
Create the script at /home/pi with the command sudo nano /home/pi/homeduino-online-installer.sh
and copy the following code into it. You can surely use any other editor or program of your choice. You certainly know what you are doing since you came that far
#!/bin/bash
# homeduino-online-installer.sh
# updating homeduino when pimatic is running.
# removing old logfile
sudo rm -rf /home/pi/homeduino-online-installer.log
# setting the date to the logfile
date &>> /home/pi/homeduino-online-installer.log
# stop pimatic daemon
sudo service pimatic stop &>> /home/pi/homeduino-online-installer.log
# getting update and upgrade
sudo apt-get -qq update &>> /home/pi/homeduino-online-installer.log
sudo apt-get -qq upgrade &>> /home/pi/homeduino-online-installer.log
# copy homeduino to homedirectory
cd /home/pi &>> /home/pi/homeduino-online-installer.log
sudo rm -rf homeduino &>> /home/pi/homeduino-online-installer.log
sudo git clone --recursive https://github.com/pimatic/homeduino.git &>> /home/pi/homeduino-online-installer.log
# flash arduino
cd homeduino &>> /home/pi/homeduino-online-installer.log
sudo make upload &>> /home/pi/homeduino-online-installer.log
# start pimatic daemon
sudo service pimatic start &>> /home/pi/homeduino-online-installer.log
exit
DONE You have made it! Congratulations!
Now add the devices to your gui and if all is working properly you should get notifications in pimatic looking like that
If you want to you can use any notification plugin to forward the update info. I am using pushover. For the infomation push I have altered the rule pimatic-update-available
and homeduino-update-available
. Check here for howto
Now you are really DONE - and I am done too … phew! lots of stuff but you get an outstanding changelog and update notification for your efforts!
Have fun with it!
Cheers
P.S.: For any comment or further help please use this thread! Thx!!