Triggered by a comment on episode 1 of this blog i decided to use Domoticz to visualize the measurements in a graph. I use Domoticz to control my home since july 2013 and it has proven to be very reliable.
To graph the weight first a “virtual sensor” must be created. First find a unique index and paste the url below in your browser:
http://domoticzip:8080/json.htm?type=command¶m=udevice&hid=2&did=60&dunit=4&
dtype=93&dsubtype=1&nvalue=0&svalue=75.0
* did=60 represents the device ID number for this device
(could be any unique number). Make a note of it.
Upon creation the device will be given an unique index.
* dtype=93 refers to the BWR102 device, a Oregon Scientific connected scale we mimic.
* svalue=75.0 refers to the weight. Every call to this URL will update the value.
After creation of the virtual sensor, push the green button to have the sensor showing up on the “Other devices” tab:
Other Devices tab:
Now the sensors are ready the BS440 program can call the sensor URL with the appropriate Device number and weight (see BS440domoticz.py). In the .ini file the Domoticz connection parameters (IP-adres and username/password) can be entered.
Now every time a user steps on the scale the weight will be logged and graphed.
To have consistent results it is advised to do your weighings at the same time of day. In my case this will be between 07:00 and 08:00 in the morning (8:00 – 11:00 in the weekends). I use an IP controlled switch based on a Sonoff ESP8266 based 220V switch flashed with ESP Easy firmware. Now Domoticz can switch on/off the Raspberry through WiFi by calling the ip address of the Sonoff like
http://ip-address/control?cmd=gpio,12,1 (=on)
http://ip-address/control?cmd=gpio,12,0 (=off)
Before switching off at 8:15 (11:15 in the weekeinds) be sure that a cron job did a shutdown earlier to not corrupt the flash card. Also when powering up, the “python BS440.py” needs to be started automatically through BS440.sh and a @reboot cron. These are the cron definitions to accomplish this:
@reboot sh /home/pi/BS440.sh > /home/pi/cronlog 2&1
0 8 * * 1,2,3,4,5 sudo shutdown -h +0
0 11 * * 0,6 sudo shutdown -h +0
A 1 minute sleep is inserted in BS440.sh to have a stable booted Raspberry before starting the bluetooth communications in background.
#!/bin/sh
cd /
cd home/pi
sleep 1m
sudo python BS440.py &
cd /