Posted on April 8, 2017 in home automation, linux, raspberryPi
This is how I solved it!
The script that show status on homepage.
<?php echo "<b>Machine status</b>"; echo "</br>"; $arr = array(5, 7, 9); foreach ($arr as &$value) { $get_data = "http://10.0.20.11/json.htm?type=command¶m=getuservariable&idx=".$value; $result = file_get_contents($get_data); $decode = json_decode($result,true); if ($decode["result"][0]["Value"] == "1"){ $icon = "green-icon.png"; } else { $icon = "red-icon.png"; } switch ($decode['result'][0]['Name']) { case "washingmachine_status": $unit = "Washing machine"; break; case "dryer_status": $unit = "Dryer"; break; case "dishwasher_status": $unit = "Dishwasher"; break; } echo "</br> " . $unit . "</br><img src=\"/wp-content/uploads/2015/12/" . $icon . "\"><em>" . $decode['result'][0]['LastUpdate'] . "</em><br>"; } ?>
The script that check my machines.
--script_time_washingmachine.lua --This script monitors the current consumption indicated by a Z-Wave plug, placed between the washingmachine and the mains outlet --It will count the amount of time that the power usage is below the triggervalue to be configured below. This indicates us that the washer has finished. --When the script thinks the washingmachine is done, it will send you a pushnotification (line #38)</code> --Change the values below to reflect to your own setup local switch_washingmachine = 'virt_wasmachine' --Name of virtual switch that will show the state of the washingmachine (on/off) local washer_status_uservar = 'washingmachine_status' local energy_consumption = 'Wasmachine' --Name of Z-Wave plug that contains actual consumption of washingmachine (in Watts) local washer_counter_uservar = 'washingmachine_counter' --Name of the uservariable that will contain the counter that is needed local idle_minutes = 5 --The amount of minutes the consumption has to stay below the 'consumption_lower' value local consumption_upper = 20 --If usage is higher than this value (Watts), the washingmachine has started local consumption_lower = 3 --If usage is lower than this value (Watts), the washingmachine is idle for a moment/done washing sWatt, sTotalkWh = otherdevices_svalues[energy_consumption]:match("([^;]+);([^;]+)") washer_usage = tonumber(sWatt) commandArray = {} --Virtual switch is off, but consumption is higher than configured level, so washing has started if (washer_usage > consumption_upper) and uservariables[washer_status_uservar] == 0 then --commandArray[switch_washingmachine]='On' commandArray['Variable:' .. washer_status_uservar]='1' print('Current power usage (' ..washer_usage.. 'W) is above upper boundary (' ..consumption_upper.. 'W), so washing has started!') commandArray['Variable:' .. washer_counter_uservar]=tostring(idle_minutes) end if (washer_usage < consumption_lower) and uservariables[washer_status_uservar] == 1 then --Washing machine is not using a lot of energy, subtract the counter commandArray['Variable:' .. washer_counter_uservar]=tostring(math.max(tonumber(uservariables[washer_counter_uservar]) - 1, 0)) print('Current power usage (' ..washer_usage.. 'W) is below lower boundary (' ..consumption_lower.. 'W), washer is idle or almost ready') print('Subtracting counter with 1, new value: ' ..uservariables[washer_counter_uservar].. ' minutes') end --Washingmachine is done if ((uservariables[washer_status_uservar] == 1) and uservariables[washer_counter_uservar] == 0) then print('Washingmachine is DONE') print('Current power usage washingmachine ' ..washer_usage.. 'W') print('Washingmachine is done, please go empty it!') commandArray['SendNotification']='Washingmachine#Washingmachine is done, please go empty it!#0' --Use Domoticz to send a notification, replace line for your own command if needed. --commandArray[switch_washingmachine]='Off' commandArray['Variable:' .. washer_status_uservar]='0' end return commandArray
Posted on February 21, 2016 in home automation, linux, raspberryPi
I have a solution, this is how i manage solve this “irritating problem”.
I assume that you have a Z-wave base, mine is a raspberryPi with a razberry chip and with software domoticz.
You shoppinglist:
1pcs Inline Smart Energy Switch from Aeon Labs
1pcs Motion sensor from Fibaro
In sweden you can get all you need at www.m.nu

Aeon Labs – Switch

Fibaro motion sensor
And I use a LUA script named script_time_PIR-tv.lua. So after 20 minutes of inactivity in livingroom, the tv shutsdown… Simply as that!
function timedifference(s) year = string.sub(s, 1, 4) month = string.sub(s, 6, 7) day = string.sub(s, 9, 10) hour = string.sub(s, 12, 13) minutes = string.sub(s, 15, 16) seconds = string.sub(s, 18, 19) t1 = os.time() t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds} difference = os.difftime (t1, t2) return difference end commandArray = {} -- Set length of time light should be on for in seconds timeon = 1200 -- Calculate time since time PIR was last activated difference = timedifference(otherdevices_lastupdate['Vardagsrum motion']) -- If the time since last activation was within 1 minute of time for light to stay on if (difference > timeon and difference < (timeon + 61)) then tempdiff = tostring(difference) tempmessage = "Switch1 Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds" print(tempmessage) -- Switch off Switch1 commandArray['Tv'] = 'Off' end return commandArray
Posted on September 10, 2015 in home automation, linux, raspberryPi
I have logging my outside temperature since 2007 and reporting it to the swedish temperature page www.temperature.nu with a uptime of 98%. It’s pretty good I must say.
I’m used 1-wire to do this but today I have shifted to wireless insteed. Why is becuse that my 1-wire have been so long in meters and act like a antenna when we have thunder, so the result is that almost all my component have fried.
So today after some programming, I now done with this installation of two wireless THGN132N sensors placed one at north and one at southeast.
As a receiver I’m using a raspberryPi with domoticz and a RFXtrx433E USB 433.92MHz Transceiver connected.
And this script take the lowest temperature and the temperatur.nu collect it from it’s textfile.
<?php
$north = exec(“wget -O – -q http://10.0.20.11/utenorr.txt”);
$east = exec(“wget -O – -q http://10.0.20.11/uteost.txt”);
if ($north < $east){
$lowest = “North”;
$temp = $north;
}
else{
$lowest = “East”;
$temp = $east;
}
echo “$lowest har lgst temp: $temp grader”;
exec(“echo ” . $temp . ” > /home/essunga/public_html/wwwroot/temperature_lowest.txt”);
?>
Posted on July 31, 2015 in home automation, linux, raspberryPi
I builded a digital photo frame in 2012 with a old TFT-screen 17″ that I had lying around.
Here comes a post about how I did it, and sharing my scripts…
Here is a video and the photo frame have a uptime for three years now.
Guide from clean install of raspbian – using 2015-05-05 version.
pi@fotoram ~ $ sudo apt-get update
pi@fotoram ~ $ sudo apt-get upgrade
Now you have the latest version of your raspbian.
Now we have to install feh. Feh is the program that display the pictures and installing php, because we are using some php-scripts.
And at least, sendmail. Because after we email a picture, we get a respond from the photoframe that the picture is received.
pi@fotoram ~ $ sudo apt-get install feh php5-cli php5-imap sendmail
Download the scripts.
PhotoFrame.zip
Okey, how does this work? First we have to disable screensaver, otherwise the screen will shutdown.
Stop text terminals from blanking
change in /etc/kbd/config these two:
BLANK_TIME=0
POWERDOWN_TIME=0
Stop Xsession from blanking
Add these lines to /etc/xdg/lxsession/LXDE-pi/autostart or /home/pi/.config/lxsession/LXDE-pi/autostart
@xset s noblank
@xset s off
@xset -dpms
and comment out line @xscreensaver -no-splash to
#@xscreensaver -no-splash
In the photoframe.zip file we have a couple of files.
bilder = folder there feh will look for pictures.
display.txt = textfile with information that will display in the bottom corner.
fetch_mail.php = A php script that fetch new pictures from gmail.
get_online_pics.sh = A script that fetch webcam pictures from the internet and put it to the bilder folder.
picslide.sh = Script that start feh at boot.
put_display.sh = Update the information in display.txt file
run_fetch_mail.sh = Script that run fetch_mail.php, I made it because sometimes it take some time to fetch a new picture from gmail. And if the service is running the system hangs. So this script look if the fetch_mail.php is running, and if it does. It won’t start a new one.
Now everything is installed and the scrips are in pi homefolder.
Now add these lines to cron.
First I like pico as a editor insteed of vim.
So change the editor
pi@fotoram ~ $ which pico # Output /usr/bin/pico
pi@fotoram ~ $ export EDITOR=/usr/bin/pico
Now run
pi@fotoram ~ $ crontab -e
Add following lines:
*/1 * * * * /home/pi/get_online_pics.sh > /dev/null 2>&1 # Get a new pictures from webcam
*/1 * * * * /home/pi/put_display.sh > /dev/null 2>&1 # Update display.txt
*/5 * * * * /home/pi/run_fetch_mail.sh > /dev/null 2>&1 # Get new pictures from Gmail
00 22 * * * /opt/vc/bin/tvservice -o > /dev/null 2>&1 # Shutdown screen at 22:00
00 05 * * * sudo reboot > /dev/null 2>&1 # Reboot the Pi at 05:00 so the screen wakes up
Now we have that running, lets add so feh starts at bootup. Go back to /etc/xdg/lxsession/LXDE-pi/autostart or /home/pi/.config/lxsession/LXDE-pi/autostart and add @/home/pi/picslide.sh at the bottom save and then reboot.
As you can see in my script, that fetch_mail.php the script is only looking for new pictures in label Fotoram. So you have to make a filter in gmail. I using
Match: from:(myemailAndOneFilterforMypartnersEmail@essunga.org)
Do: Jump over Inbox, Use Label "Fotoram"
Do you have any questions or problems, please write a comment.