More is commig





























This is how I solved it!

The script that show status on homepage.

echo "<b>Machine status</b>";
echo "</br>";
$arr = array(5, 7, 9);
foreach ($arr as &$value) {
$get_data = "".$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";
    case "dryer_status":
        $unit = "Dryer";
    case "dishwasher_status":
        $unit = "Dishwasher";
	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.

--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 &gt; consumption_upper) and uservariables[washer_status_uservar] == 0 then
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)
if (washer_usage &lt; 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')
--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['Variable:' .. washer_status_uservar]='0'
return commandArray

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

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
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 &gt; timeon and difference &lt; (timeon + 61)) then
tempdiff = tostring(difference)
tempmessage = "Switch1 Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
-- Switch off Switch1
commandArray['Tv'] = 'Off'
return commandArray


I have logging my outside temperature since 2007 and reporting it to the swedish temperature page 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 collect it from it’s textfile.


$north = exec(“wget -O – -q”);
$east = exec(“wget -O – -q”);

if ($north < $east){
$lowest = “North”;
$temp = $north;
$lowest = “East”;
$temp = $east;

echo “$lowest har lgst temp: $temp grader”;

exec(“echo ” . $temp . ” > /home/essunga/public_html/wwwroot/temperature_lowest.txt”);




My webbserver act as a torrentclient as well.

To start rtorrent in background I using the command screen to do this.

This is how I do:
In terminal type,

bash-4.2$ screen -dmS rtorrent rtorrent

Your have now started rtorrent in a screen named rtorrent, how to access is just type

bash-4.2$ screen -r rtorrent

and there you have it.
And to exit, hold on Ctrl and A release and then press D. Now your are out of rtorrent screen and it still running i background.

Are you like me that you have a habbit to listen to music when programming in linux and you struggle with mplayer to stream a radiostation?

In your home folder your have a file that names .bashrc if your don’t have one just create one. That file in loaded when you log on and here you can create short commands.

Mine look like this.

alias litefm='mplayer -playlist'
alias radioseven='mplayer -playlist'
alias xterm='xterm -bg black -fg white'
alias jonathan='cvlc &'
alias framsidan='cvlc &'

Add these line to your file and logout and now login and try command litefm in your terminal. And now your are streaing a radiostation from Trollhättan – Sweden.

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.

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:

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 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. = A script that fetch webcam pictures from the internet and put it to the bilder folder. = Script that start feh at boot. = Update the information in display.txt file = 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/ > /dev/null 2>&1 # Get a new pictures from webcam
*/1 * * * * /home/pi/ > /dev/null 2>&1 # Update display.txt
*/5 * * * * /home/pi/ > /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/ 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:(
Do: Jump over Inbox, Use Label "Fotoram"

Do you have any questions or problems, please write a comment.

Here is one simple way to unzip multiple zip files in linux thru console.

bash-4.2$ for i in *.zip; do unzip -d $i.folder $i; done

Here is how I build my alarm, quite simple to do and to get push messages from prowl or mail.
For Gateway I use a moteino connected to a raspberryPi model B+ as you can see from the pictures below.

Feel free to ask questions or guidance if you want to build one by you own.

The work in pictures:

Mailbox alarm

The result

Prowl push msg

Mailbox moteino schematic

Arduino IDE Code:

    #include <RFM69.h>
    #include <SPI.h>
    #include <LowPower.h>
    #include <PinChangeInt.h>        // Two lines to include pinChangeInt library
    // NOTE!  The logic of mailbox OPEN vs CLOSED has been reversed for D4
    // D4 = HIGH is Mailbox OPENED (magnetic switch open)
    // D4 = LOW  is Mailbox CLOSED (magnetic switch closed)
    #define NODEID 2 // unique for each node on same network
    #define GATEWAYID 1
    #define NETWORKID 100 // the same on all nodes that talk to each other
    #define FREQUENCY RF69_868MHZ
    #define ENCRYPTKEY "sampleEncryptKey" // exactly the same 16 characters/bytes on all nodes!
    #define ACK_TIME 30 // max # of ms to wait for an ack
    #define LED 9 // Moteinos have LEDs on D9
    #define SERIAL_BAUD 115200
    #define D4 4
    #ifdef SERIAL_EN
      #define DEBUG(input)   {Serial.print(input); delay(1);}
      #define DEBUGln(input) {Serial.println(input); delay(1);}
      #define DEBUG(input);
      #define DEBUGln(input);
    RFM69 radio;
    bool promiscuousMode = false; // Set to 'true' to sniff all packets on the same network
    bool sentOpen = true;
    bool stateCheck=LOW;
    uint32_t switchTime=0;      // variable to monitor when the switch last changed state (for debouncing)
    #define  DEBOUNCE_TIME  50  // give it 50 mS to debounce a noisy switch
    // Add function to catch interrupt, doesn't need to do anything as the interrupt is all that's needed to wakeup
    void wakeUp(void)   
    void setup()
    //Setup the pins
      pinMode(LED, OUTPUT);
      pinMode(D4, INPUT_PULLUP);  // TOMWS: Use internal pullup as it's easier than adding an external one...
    //Start the Serial
    //Initialize the radio
      #ifdef IS_RFM69HW
      //radio.setHighPower(); // Uncomment only for RFM69HW!
      radio.encrypt(ENCRYPTKEY); // Turn encryption ON
      radio.promiscuous(promiscuousMode);  // TOMWS: This is not necessary if not using this mode
      char buff[50];
      sprintf(buff, "\nTransmiting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
    void loop()
      if (digitalRead(D4) == HIGH)  // If the mailbox is opened
        switchTime = millis();   // record when we saw the switch change state
        stateCheck = LOW;
        if (sentOpen == false)  // have we already sent this?
          // no, send it now
          if (radio.sendWithRetry(GATEWAYID, "MAIL:OPN", 8))
            Serial.println(" nothing...");
            // Blink(LED,3);
          } else
            Serial.println("Sending Open mailboxstatus to gateway..");
          sentOpen = true;
          radio.sleep();  // we're done with the radio, make it sleep to save power immediately
      } else 
        switchTime = millis();   // record when we saw the switch change state
        stateCheck = HIGH;
        if (sentOpen == true)  // have we already sent this?
          // no, send it now
          if (radio.sendWithRetry(GATEWAYID, "MAIL:CLS", 8))
            Serial.println(" nothing...");
          } else
            Serial.println("Sending closed, once... ");
          sentOpen = false;
          radio.sleep();  // we're done with the radio, make it sleep to save power immediately
      while ((switchTime-millis()) < DEBOUNCE_TIME)  // debounce the switch
        if (digitalRead(D4) == stateCheck) switchTime = millis();  // if we sense a 'bounce' reset the timer
      Serial.flush();  // need to do before sleeping.
      // Allow wake up pin to trigger interrupt on either edge.
      PCintPort::attachInterrupt(D4, wakeUp, CHANGE);  // New code to trap interrupt on pin change
      LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);  // Changed to SLEEP_FOREVER so that only interrupts wake up, no WDT used
      // WOKEN UP!  Disable further interrupts until debounced
      PCintPort::detachInterrupt(D4);  // disable interrupts until debounced
    void Blink(byte PIN, int DELAY_MS) // Local led blinking function
     // pinMode(PIN, OUTPUT);
     // digitalWrite(PIN,HIGH);
     // delay(DELAY_MS);
     // digitalWrite(PIN,LOW);

Shopping list:
Kjell o Co
39780 Batterycase 4xR6 (AA) (fits perfect in the Box, had to remove some plastic)
89024 Box Höjd: 20 mm
42480 AA Litium 4-pack

next posts >>