Page 1 of 1

Code for Energenie LAN Powerstrip

Posted: Sunday 30 March 2014 22:01
by whiteduck
All,

Not implemented this yet but wanted to share something that could be useful:
https://energenie4u.co.uk/index.php/cat ... ct/ENER019

Found it cheapest at:
http://www.hitari.co.uk/energenie-lan-p ... ystem.html

You don't need this if you have RFXCom as I've seen elsewhere on this forum that you can control a cheaper unit via 433MHz RF.

However to control over the LAN from Linux the HOWTO states:
To login:

Code: Select all

$ wget --post-data 'pw=smartlab' 'http://nn.nn.nn.nn/login.html' -O foo.html --delete-after
To switch Socket3 ON:

Code: Select all

$ wget --post-data 'cte1=&cte2=&cte3=1&cte4=' 'http://nn.nn.nn.nn' -O foo.html --delete-after
To switch Socket3 OFF:

Code: Select all

$ wget --post-data 'cte1=&cte2=&cte3=0&cte4=' 'http://nn.nn.nn.nn' -O foo.html --delete-after
To logout:

Code: Select all

$ wget 'http://nn.nn.nn.nn/login.html' -O foo.html –-delete-after
Best regards
Ian

Re: Code for Energenie LAN Powerstrip

Posted: Monday 31 March 2014 16:56
by SweetPants
UK only?

Re: Code for Energenie LAN Powerstrip

Posted: Monday 31 March 2014 23:59
by whiteduck
No seen EU devices also… http://energenie.com/item.aspx?id=7557

Re: Code for Energenie LAN Powerstrip

Posted: Wednesday 02 April 2014 18:49
by SweetPants
whiteduck wrote:No seen EU devices also… http://energenie.com/item.aspx?id=7557
Great, I ordered one, arrives in 2-3 days

Re: Code for Energenie LAN Powerstrip

Posted: Saturday 05 April 2014 14:19
by whiteduck
Cool - let me know how you get on. I guess we should also poll the device to ensure Domoticz shows current status.

Re: Code for Energenie LAN Powerstrip

Posted: Saturday 05 April 2014 16:10
by SweetPants
Damn, received the LAN Powerstrip unit today, but it does not show any signs of live on the LAN interface. it looks like it is DOA. Will ask for a new one next week.

Re: Code for Energenie LAN Powerstrip

Posted: Saturday 05 April 2014 17:39
by whiteduck
Did you try resetting it - also may be the cable as the RJ45 is quite tight on this one - needs a straight through cable.

Re: Code for Energenie LAN Powerstrip

Posted: Saturday 05 April 2014 17:51
by whiteduck
I have written a (basic) Bash script to control this - feel free to use and modify at your own risk :)
Note: I assume wget is in default path and do no error checks...

Firstly you need to define 4 dummy switches in Domoticz. I called mine Ener1,2,3,4
I then have four lua scripts - ener1,2,3,4 - the example below is for the first - just change the parameters for 2,3,4 - but I guess you could use a single script.

I put my installation under /root so modify this for your own setup.

script_device_ener1.lua

Code: Select all

commandArray = {}
if (devicechanged['Ener1'] == 'On') then
	os.execute('/root/domoticz/scripts/energenie 1 on')
end
if (devicechanged['Ener1'] == 'Off') then
	os.execute('/root/domoticz/scripts/energenie 1 off')
end
return commandArray
Then the Bash code looks like this - note this doesn't do any error checking!

Code: Select all

#!/bin/bash
exec > /dev/null 2>&1 # Redirect all output to null

IP=192.168.0.254
URL=http://$IP
SOCK=$1
CMD=$2
PASS=yourpass

if [ "$CMD" = "on" ]
then
 ACTION=1
else
 ACTION=0
fi

# Login first
wget --post-data pw=$PASS $URL/login.html -O foo.html --delete-after

# Send command
case $SOCK in
 "1" ) wget --post-data "cte1=$ACTION&cte2=&cte3=&cte4=" $URL -O foo.html --delete-after ;;
 "2" ) wget --post-data "cte1=&cte2=$ACTION&cte3=&cte4=" $URL -O foo.html --delete-after ;;
 "3" ) wget --post-data "cte1=&cte2=&cte3=$ACTION&cte4=" $URL -O foo.html --delete-after ;;
 "4" ) wget --post-data "cte1=&cte2=&cte3=&cte4=$ACTION" $URL -O foo.html --delete-after ;;
esac

# Logout
wget ${URL}/login.html -O foo.html --delete-after

exit 0;
Something to do would be to check the status of the sockets and update Domoticz if something else changes them to on or off.

Good luck!

Re: Code for Energenie LAN Powerstrip

Posted: Monday 28 April 2014 16:45
by SweetPants
whiteduck wrote:Did you try resetting it - also may be the cable as the RJ45 is quite tight on this one - needs a straight through cable.
It was broken, received another one today. This one is working

Re: Code for Energenie LAN Powerstrip

Posted: Monday 28 April 2014 17:04
by SweetPants
whiteduck wrote:I have written a (basic) Bash script to control this - feel free to use and modify at your own risk :)
Great, this works fine for now, thanks.

Re: Code for Energenie LAN Powerstrip

Posted: Thursday 26 November 2015 21:54
by JohnS
My system runs on a Raspberry Pi 2. I have one of these Energenie LAN controlled adapters and here is another way of controlling it in Linux, using a utility I found.

1. Download and install the egctl utility written by unterwulf

Code: Select all

cd ~
git clone https://github.com/unterwulf/egctl.git
cd egctl
make
sudo make install
2. Create the config file:

Code: Select all

sudo nano /etc/egtab
enter one line for each device you have, in the format
devicename protocol ipaddress port password
for example:

Code: Select all

4way pms21 192.168.1.56 5000 pa55w0rd
Now ctrl-X and write the file.

3. Check it works

Code: Select all

egctl devicename

The response will indicate the current status of the switches

4. Using in Domoticz

You must always provide instructions for each of the switches 1 to 4
on = turn switch on regardless
off = turn switch off regardless
left = leave switch as is
toggle = change switch to the opposite state

eg: egctl 4way on off on toggle

In domoticz, create a dummy hardware device.
Create a dummy switch
In the "on action" or "off action" fields enter for example

Code: Select all

script:///home/pi/egctl/egctl 4way on left left left
Hope that helps!

Re: Code for Energenie LAN Powerstrip

Posted: Tuesday 17 January 2017 12:18
by FxWork
Great, it works very well.

Thanks 4 that