Energenie LAN Management Power Strip (4-Way) - Plug in (Idea)

I tried different urls with ZeroBrane LUA test environment and they all seemed to work. I then tried it with my Internet browser and the page doesn’t respond any more! I think messing about with testing code has partially hung the EnerGenie – not a good sign for robust reliability… Now that woud explain why Vera is seeing timeouts :wink:
Wierdly the iPhone app still definitely works and control the switches, but presumably this uses a different port via the cloud service.
I’ll have another go tomorrow. If the EnerGenie doesn’t recover overnight, I’ll have to power cycle it (or maybe there is a reset button?).

Some success !!!

Using a very simple ipad app, I can turn a socket on and off by sending (POST) the following to this URL

http://192.168.1.90/status.html

Parameter pw = 1
Parameter cte2 = 0 (for off)

It only bloody works - socket 2 is turned off !!

Now, I’m bound to have missed something obvious, but so far, so good. Is anyone able to verify ?

Using that simply app on the iPad…

It looks like I have to POST the pw=1 parameter to this URL http://192.168.1.90/login.html

And then once logged in i can send the socket command cte1=0 to this URL http://192.168.1.90/status.html

Seems like different commands to different URLs.

The login requests seems to timeout after a while, I’ll need to try and work out how long that is.

I’m not going to be able to do much more during today, but I will hopefully try later

After pressing reset button on the Energenie, the web front end worked ok. However, as soon as I run this Luup code in Vera, the Energiene web server locks up again after a single attempt. I don’t understand why Vera causes the Energenie to lock up in contrast to same code run from ZeroBrane lua does not. For me, I think this is a dead end to using port 80. Perhaps using the separate API for Power Manager Client on port 5000 is the better way to go, but far too complex for me to attempt it.

local url = require("socket.url")
local socket = require("socket")
local http = require("socket.http")
local ltn12 = require("ltn12")
local postBody = "server=GENIE&pw=1"
local controlURL = "http://192.168.0.246/energenie.html"

-- 5 Second timeout
http.TIMEOUT = 5

local resultTable = {}
local status, statusMsg = http.request{
    url = controlURL,
    sink = ltn12.sink.table(resultTable),
    method = "POST",
    headers = {
                        ["Accept"] = "*/*",
                        ["Accept-Encoding"] = "gzip, deflate",
                        ["Accept-Language"] = "en-us",
                        ["Content-Type"] = "application/x-www-form-urlencoded",
                        ["Content-Length"] = postBody:len()
                },
    source = ltn12.source.string(postBody),
  }

luup.log("Status Message1 = " .. tostring(statusMsg))
socket.sleep(2)
luup.log("Status Message2 = " .. tostring(statusMsg))

I’m not able to have a play at the moment, but I can’t help but think the code could be much easier than that. Using the iPad, it looks like two basic POST commands were sent and it worked?!?

UPDATE - I was hoping it could be something like this… Taken from here → http://wiki.micasaverde.com/index.php/Luup_Scenes_Events#Invoke_HTTP_URL_with_POST_request_.28Method_3.29

[code]local http = require(“socket.http”)
http.TIMEOUT = 5
result, status = http.request(“http://192.168.1.90/login.html”, “pw=1”)

luup.call_delay(“Socket2on”,10)

function Socket2on()
http.TIMEOUT = 5
result, status = http.request(“http://192.168.1.90/status.html”, “cte2=1”)
end
[/code]

… But all this seems to have done is make my Energenie unresponsive now :slight_smile:

UPDATE 2 - it looks like the Energenie can only have one session (from one device running) at any one time, I attempted another login from my PC while I was using it on my iPad - so it tells you."

Impossible to login - there is an active session with this device at the moment"

It’s poosible that could play a key part in the testing. If I have the iPad logged in when testing code on Vera…

Wow, coming back to this thread that I had started a while back - I’ve stumbled across something that works and it seems remarkably simple. Just a short line of code which you can run via the command line :Dn - which mean you can call these in vera by using os.execute(“curl command”)

The first thing you need to do is login (the default password is 1, so I have left it as that for those examples)

It’s seems you can do that either via curl,

curl -s -d "pw=1" http://192.168.1.90/login.html

or wget

wget -q -O - --post-data="pw=1" http://192.168.1.90/login.html 

And the to turn the sockets on or off you set the value of your target to either 1 or 0 e.g.

Turn on socket 4 (via curl)

curl -s -d "cte4=1" http://192.168.1.90/

Turn off socket 4 (via curl)

curl -s -d "cte4=0" http://192.168.1.90/

Turn on socket 4 (via wget)

wget -q -O - --post-data="cte4=1" 'http://192.168.1.90/'

Turn off socket 4 (via wget)

wget -q -O - --post-data="cte4=0" 'http://192.168.1.90/'

Now if anyone is able to work this into a plug in, when the login is refreshed every few minutes . There seems to be a way to check the state of the sockets, but I could not get this to work

curl -s -d "pw=1" http://192.168.1.90/login.html | \ sed -n -E -e 's/.*var sockstates = \[([01]),([01]),([01]),([01])\].*/\1 \2 \3 \4/p' | \ sed -e 's/0/off/g' -e 's/1/on /g' | \ xargs printf -- "\n-1- -2- -3- -4-\n%3s %3s %3s %3s\n" wget -q -O - --post-data="pw=1" http://192.168.1.90/login.html | \ sed -n -E -e 's/.*var sockstates = \[([01]),([01]),([01]),([01])\].*/\1 \2 \3 \4/p' | \ sed -e 's/0/off/g' -e 's/1/on /g' | \ xargs printf -- "\n-1- -2- -3- -4-\n%3s %3s %3s %3s\n"

A big thank you to the following sources

[ul][li]https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=https%3A%2F%2Fwiki.ffdo.de%2FTechnik%2FRichtfunk%2FGeraetekonfiguration%2FEG-PM2-LAN[/li]
[li]Code for Energenie LAN Powerstrip - Domoticz

It took me 8 years, 2 months to get there, but I finally created a plugin for Energenie LAN Switch :slight_smile:

1 Like