Page 1 of 37

Nefit Easy™

Posted: Thursday 31 December 2015 1:00
by Holland
Hi,

As just mentioned in this thread, viewtopic.php?f=34&t=755&p=66969&hilit=nefit#p66969, Robert Klep has developed a client that can access the Nefit Easy. For more info please go to https://github.com/robertklep/nefit-easy-client and http://gathering.tweakers.net/forum/lis ... 8#45516548

To install the Nefit Easy client on a Pi please follow the below procedure:

The Nefit Client requires Node 4.0 or newer. Problem is the most recent version of wheezy comes with a rather old version of node (think v0.12 or something). The latest stable version of Node is v5.3.0. Install that version by doing this for the Pi 2:

1. node -v
2. wget https://nodejs.org/dist/v5.3.0/node-v5. ... v7l.tar.gz
3. tar -xvf node-v5.3.0-linux-armv7l.tar.gz
4. cd node-v5.3.0-linux-armv7l
5. sudo cp -R * /usr/local/
6. node -v

At step 6 it should show v5.3.0

Then continue with the installation of the Nefit Easy Client.

1. git clone https://github.com/robertklep/nefit-eas ... server.git (if you need to update later on, issue the following: git pull https://github.com/robertklep/nefit-eas ... server.git)
2. cd nefit-easy-http-server
3. sudo npm i nefit-easy-http-server -g
4. export NEFIT_SERIAL_NUMBER= insert your serial number here
5. export NEFIT_ACCESS_KEY= you get the point
6. export NEFIT_PASSWORD= ""

The installation is now done.

After the above I ran an example script which showed the following: Yes succes!

pi@raspberrypi ~/nefit-easy-client $ node example/current-status.js
Temperature is set to 15.0°C, current is 19.9°C.
Outside temperature is 7.0°C.
System pressure is 0.9 bar.

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 7:49
by jeroenkl
Great! Thanks!

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 8:29
by TazDevl
awesome!

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 9:53
by jeroenkl
in case you want to install node.js in on a Raspberry Pi 1 model B revision 2:

pi@raspberrypi $ wget https://nodejs.org/dist/v5.3.0/node-v5. ... v6l.tar.gz
pi@raspberrypi $ tar -xvf node-v5.3.0-linux-armv6l.tar.gz
pi@raspberrypi $ cd node-v5.3.0-linux-armv6l/
pi@raspberrypi ~/node-v5.3.0-linux-armv6l $ sudo cp -R * /usr/local/
pi@raspberrypi ~/node-v5.3.0-linux-armv6l $ node -v
v5.3.0

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 11:32
by dorenberg
great news. Will follow this thread!!!!

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 11:44
by geezerrr
This makes me happy +1
Hope we can control the nefit easy with Domoticz soon

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 13:30
by SweetPants
Can already read the Nefit Easy thermostat with this library. great job

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 14:23
by Holland
We can make it even more simple with the CLI.

If you issue the following from the nefit client directory; ./bin/easy status

The following is returned, which is basically a JSON string. Now I need to find out how to get this into Domoticz. Any help is appreciated :)

{"user mode":"clock","clock program":"auto","in house status":"ok","in house temp":19,"boiler indicator":"off","control":"room","temp override duration":0,"current switchpoint":24,"ps active":false,"fp active":false,"temp override":false,"holiday mode":false,"boiler block":null,"boiler lock":null,"boiler maintainance": null,"temp setpoint":19,"temp override temp setpoint":19.5,"temp manual setpoint":19.5,"hed enabled":null,"hed device at home":null,"outdoor temp":10,"outdoor source type":"virtual"}

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 15:15
by jannl
json decoding will not be that hard using perl or so.

Works great, however, how to the environment vars correctly from a script (sh/bash or perl)

Edit: never mind, was a path setting and type

Perl code below sets a temp value in Domoticz.
Highly depends on the output of the status command not being changed.
Now just finding a way to do this regularly

Code: Select all

#!/usr/bin/perl
    use strict;
    use v5.14;
    use strict;                     # Good practice
    use warnings;                   # Good practice
    use Time::Local;

    my $domoticz = "192.168.1.2:8080";  # ip and port of your Domoticz server

    my @element_array=();
    my $nr_elements=0;
    my $nefit_cmd = "/home/pi/domoticz/nefit-easy-client/bin/easy status";
    $ENV{NEFIT_SERIAL_NUMBER}="serial";
    $ENV{NEFIT_ACCESS_KEY}="acces key";
    $ENV{NEFIT_PASSWORD}='passwd';

#system ( "set | grep -i nefit");
    # Get the JSON url
    my $json=  `$nefit_cmd`;
    #remove first and last character
    $json =~ s/^.//s ;
    $json =~ s/.$//s ;
    #print("$json\n");
    my @elements = split(/,/, $json);

    foreach my $f ( @elements )
    {
        my @lines = split(/:/,$f);
        #always 2 element!!
        $lines[0] =~ s/^\"//s ;
        $lines[0] =~ s/\"$//s ;
        $lines[1] =~ s/^\"//s ;
        $lines[1] =~ s/\"$//s ;
        $element_array[$nr_elements][0] = $lines[0];
        $element_array[$nr_elements][1] = $lines[1];
        $nr_elements++;
        #print("$lines[0] -> $lines[1]\n");
    }
print("$nr_elements\n");
for (my $i=0;$i < $nr_elements;$i++)
{
        if ( $element_array[$i][0] =~ m/in house temp/ )
        {
                #print ("$element_array[$i][0] -> $element_array[$i][1]\n");
                `curl -s "http://$domoticz/json.htm?type=command&param=udevice&idx=141&nvalue=0&svalue=$element_array[$i][1]"`;
        }
}


Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Thursday 31 December 2015 16:50
by jannl
Remaining question is, how secure is this.
With the environment vars, basically everyone who has them can see what your nefit is doing and where it is doing that.
As in: vacation program is running.....

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Friday 01 January 2016 21:39
by ThinkPad
Holland wrote:We can make it even more simple with the CLI.

If you issue the following from the nefit client directory; ./bin/easy status

The following is returned, which is basically a JSON string. Now I need to find out how to get this into Domoticz. Any help is appreciated :)

{"user mode":"clock","clock program":"auto","in house status":"ok","in house temp":19,"boiler indicator":"off","control":"room","temp override duration":0,"current switchpoint":24,"ps active":false,"fp active":false,"temp override":false,"holiday mode":false,"boiler block":null,"boiler lock":null,"boiler maintainance": null,"temp setpoint":19,"temp override temp setpoint":19.5,"temp manual setpoint":19.5,"hed enabled":null,"hed device at home":null,"outdoor temp":10,"outdoor source type":"virtual"}
I would say: Python.
Unfortunately i'm not a programmer (otherwise i would help), but i know that parsin JSON with Python is quite easy.

See this script for example: http://domoticz.com/wiki/Mindergas.nl#The_Python_way which parses JSON-output from Domoticz:
meterstand = device_data['result'][0]['Counter']
I think that is a good way to start parsing the values and putting them into virtual sensors in Domoticz.

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Friday 01 January 2016 21:47
by mvveelen
Wow, this looks promising! I hope this will be developed more and will also be available on a Synology without too much hassle (i.e. installing programs and such).

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 0:23
by pepijn
I started this this evening and have it running using Node-RED.
Schermafbeelding 2016-01-02 om 00.20.25.png
Schermafbeelding 2016-01-02 om 00.20.25.png (44.31 KiB) Viewed 30141 times
When finished i will post a more detailed description here
Schermafbeelding 2016-01-02 om 00.20.34.png
Schermafbeelding 2016-01-02 om 00.20.34.png (27.36 KiB) Viewed 30141 times

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 10:17
by kraades
jeroenkl wrote:in case you want to install node.js in on a Raspberry Pi 1 model B revision 2:
Just wondering. Why does the package manager not work? I always end up with a 0.* version. :|

From https://nodejs.org/en/download/package-manager/:

Code: Select all

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
mvveelen wrote:Wow, this looks promising! I hope this will be developed more and will also be available on a Synology without too much hassle (i.e. installing programs and such).
There is a node package available from SynoCommunity but it is outdated. You could also compile node yourself for your platform. If you have a Synology that supports docker you could probably also use the node docker image.
pepijn wrote:I started this this evening and have it running using Node-RED.
Schermafbeelding 2016-01-02 om 00.20.25.png
When finished i will post a more detailed description here
Schermafbeelding 2016-01-02 om 00.20.34.png
Thanks, I didn't even know Node-RED was installed by default until I read your post. :D

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 11:08
by pepijn
Here is my quick and dirty solution for now:

Step 1) Install Robert Klep's piece of magic
See: https://github.com/robertklep/nefit-easy-client
I used

Code: Select all

npm install robertklep/nefit-easy-client -g
This will install the 'easy' command-line tool.

Step 2) Communicate to your easy
The command line to get the status of your Nefit boiler is

Code: Select all

easy status
For now i just created a small bash script that just sets the environment variables and executes the command.

/opt/nefit/nefit-status

Code: Select all

export NEFIT_SERIAL_NUMBER='XXXXX'
export NEFIT_ACCESS_KEY='XXXXXX'
export NEFIT_PASSWORD='XXXX'
easy status


There's also a script to set the temperature

/opt/nefit/nefit-set

Code: Select all

export NEFIT_SERIAL_NUMBER='XXXXX'
export NEFIT_ACCESS_KEY='XXXXXX'
export NEFIT_PASSWORD='XXXX'
easy set temperature "$*"
Don't forget to use chmod +X to make te scripts executable :)

Step 3) Create virtual sensors
Right now create 3 Virtual sensors, (Setpoint, Temperature and Text) and write down the IDX values
Schermafbeelding 2016-01-02 om 10.33.41.png
Schermafbeelding 2016-01-02 om 10.33.41.png (32.53 KiB) Viewed 30087 times
Step 4) Node-RED
I used Node-RED to parse the Nefit Easy JSON to Domoticz and to change the setpoint on the LUA

Here is my flow:

Code: Select all

[{"id":"22a46350.4b5c8c","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":""},{"id":"8b0bfef4.74f4","type":"inject","z":"b83a61b3.47c5a","name":"Update","topic":"nefit-update","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"x":92,"y":40,"wires":[["b358d0b9.4ca73"]]},{"id":"b358d0b9.4ca73","type":"exec","z":"b83a61b3.47c5a","command":"/opt/nefit/nefit-status","addpay":false,"append":"","useSpawn":"","name":"Nefit Status","x":255.44443702697754,"y":39.666669845581055,"wires":[["8f9f7e3a.70608"],[],[]]},{"id":"3876c9bf.c78936","type":"debug","z":"b83a61b3.47c5a","name":"","active":true,"console":"true","complete":"true","x":841.111083984375,"y":127.44444274902344,"wires":[]},{"id":"8f9f7e3a.70608","type":"function","z":"b83a61b3.47c5a","name":"Update Domoticz","func":"node.log(\"Nefit Easy to Domoticz Update\")\n\n// Configuration\nconst DomoticzServer = '172.30.0.10'\nconst DomoticzPort = '80'\n\nconst IDX_SetPoint = 160\nconst IDX_RoomTemp = 161\nconst IDX_Pressure = 162\nconst IDX_Indicator = 163\n\nvar NefitJSON = JSON.parse(msg.payload);\n\nvar setpoint_msg = {}\nvar temp_msg = {}\nvar pressure_msg = {}\nvar indicator_msg = {}\n\n// Update\nif (msg.topic == 'nefit-update')  {\n    temp_msg.url = 'http://' + DomoticzServer + ':' + DomoticzPort + '/json.htm?type=command&param=udevice&idx=' + IDX_RoomTemp + '&nvalue=0&svalue=' + NefitJSON['in house temp']\n    indicator_msg.url = 'http://' + DomoticzServer + ':' + DomoticzPort + '/json.htm?type=command&param=udevice&idx=' + IDX_Indicator + '&nvalue=0&svalue=' + NefitJSON['boiler indicator']\n}\n\n//if (msg.topic == 'nefit-pressure')  {\n//    pressure_msg.url = 'http://' + DomoticzServer + ':' + DomoticzPort + '/json.htm?type=command&param=udevice&idx=' + IDX_Pressure + '&nvalue=0&svalue=' + NefitJSON['pressure']\n//}\n\nreturn [setpoint_msg, temp_msg, pressure_msg, indicator_msg];","outputs":"4","noerr":0,"x":447.88887786865234,"y":35,"wires":[[],["3ac46950.c53b96"],[],["b19896ef.4e6768"]]},{"id":"3ac46950.c53b96","type":"http request","z":"b83a61b3.47c5a","name":"Domoticz","method":"GET","ret":"txt","url":"","x":825.7777709960938,"y":33.66667366027832,"wires":[["3876c9bf.c78936"]]},{"id":"1caaaa11.e35556","type":"mqtt in","z":"b83a61b3.47c5a","name":"domoticz/out/#","topic":"domoticz/out/#","broker":"22a46350.4b5c8c","x":85,"y":276,"wires":[["577c156d.a883ec"]]},{"id":"577c156d.a883ec","type":"function","z":"b83a61b3.47c5a","name":"de-jsonify","func":"var payload = JSON.parse(msg.payload);\nreturn payload;","outputs":1,"noerr":0,"x":251,"y":276,"wires":[["342ad05e.cbd53"]]},{"id":"23467d6a.dcb982","type":"debug","z":"b83a61b3.47c5a","name":"","active":false,"console":"false","complete":"true","x":849,"y":344,"wires":[]},{"id":"50e0c648.af1f38","type":"function","z":"b83a61b3.47c5a","name":"","func":"msg.payload = msg.svalue1\nreturn msg;","outputs":1,"noerr":0,"x":596.4444580078125,"y":276.33331298828125,"wires":[["a97981c8.56868"]]},{"id":"342ad05e.cbd53","type":"switch","z":"b83a61b3.47c5a","name":"filter Setpoint IDX","property":"idx","rules":[{"t":"eq","v":"160"}],"checkall":"true","outputs":1,"x":429.4444274902344,"y":275.5555419921875,"wires":[["50e0c648.af1f38"]]},{"id":"b19896ef.4e6768","type":"switch","z":"b83a61b3.47c5a","name":"pressure URL","property":"url","rules":[{"t":"nnull"}],"checkall":"true","outputs":1,"x":661,"y":116.66667175292969,"wires":[["3ac46950.c53b96"]]},{"id":"a97981c8.56868","type":"exec","z":"b83a61b3.47c5a","command":"/opt/nefit/nefit-set","addpay":true,"append":"","useSpawn":"","name":"Nefit Set Temp","x":770,"y":276,"wires":[["23467d6a.dcb982"],[],[]]}]
When importing it should look like this:
Schermafbeelding 2016-01-02 om 10.39.25.png
Schermafbeelding 2016-01-02 om 10.39.25.png (45.89 KiB) Viewed 30087 times
Now you need to adjust the configuration by editing the 'Update Domoticz' function in Node-RED.
Schermafbeelding 2016-01-02 om 10.59.15.png
Schermafbeelding 2016-01-02 om 10.59.15.png (25.05 KiB) Viewed 30087 times
Change your Domoticz server IP address and port and use the IDX values from Step 3 to set IDX_SetPoint (Setpoint virtual Sensor), IDX_RoomTemp (Temperature Virtual Sensor) and IDX_Indicator (Text Virtual Sensor)

Now you are ready to deploy the flow and start testing :)

Notes:
  • The use of these command line scripts is a bit buggy but since the Nefit Easy Client is written in NodeJS it should be possible to use it in Node-RED directly.
  • Set your thermostate to manual when using setpoints in Domoticz. If you use a clock program on the easy and adjust the setpoint from within Domoticz. The clock program will overwrite the setpoint on your easy.

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 11:34
by kraades
Thanks!

About the last note you mention.
It should also be possible with a clock program in place.
See https://github.com/robertklep/nefit-eas ... -168378270.

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 12:51
by pepijn
True :)

So if you change the script /opt/nefit/nefit-set to

Code: Select all

export NEFIT_SERIAL_NUMBER='XXXX'
export NEFIT_ACCESS_KEY='XXXX'
export NEFIT_PASSWORD='XXXX'

easy put /heatingCircuits/hc1/temperatureRoomManual \'{\"value\":$*}\'
easy put /heatingCircuits/hc1/manualTempOverride/status '{"value":"on"}'
easy put /heatingCircuits/hc1/manualTempOverride/temperature \'{\"value\":$*}\'
You can also change the setpoint when a clock program is used. But note, if the clock program changes the temperature (or you change it on the themostat/ easy app), te setpoint in Domoticz will not be changed.

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 13:51
by kraades
There has been an update.
https://github.com/robertklep/nefit-eas ... e8da0b872e
Set temparature should now work.
No need for the workaround. Sorry... :?

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Saturday 02 January 2016 14:03
by pepijn
No problem ;)

Re: Nefit Easy™ client library (How to install on the Pi)

Posted: Sunday 03 January 2016 1:04
by pepijn
A small update on my Node-RED flow
Schermafbeelding 2016-01-03 om 01.05.59.png
Schermafbeelding 2016-01-03 om 01.05.59.png (79.81 KiB) Viewed 29952 times

Code: Select all

[{"id":"22a46350.4b5c8c","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":15,"cleansession":true,"willQos":"0","birthQos":"0"},{"id":"8b0bfef4.74f4","type":"inject","z":"b83a61b3.47c5a","name":"","topic":"nefit-update","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"x":178.00001525878906,"y":116,"wires":[["b358d0b9.4ca73"]]},{"id":"b358d0b9.4ca73","type":"exec","z":"b83a61b3.47c5a","command":"/opt/nefit/nefit-status","addpay":false,"append":"","useSpawn":"","name":"Nefit Status","x":454.4444580078125,"y":116.66667175292969,"wires":[["6ebefa6b.914104"],[],[]]},{"id":"3876c9bf.c78936","type":"debug","z":"b83a61b3.47c5a","name":"","active":false,"console":"true","complete":"true","x":805.111083984375,"y":164.44444274902344,"wires":[]},{"id":"1caaaa11.e35556","type":"mqtt in","z":"b83a61b3.47c5a","name":"domoticz/out/#","topic":"domoticz/out/#","broker":"22a46350.4b5c8c","x":85,"y":276,"wires":[["577c156d.a883ec"]]},{"id":"577c156d.a883ec","type":"function","z":"b83a61b3.47c5a","name":"de-jsonify","func":"var payload = JSON.parse(msg.payload);\nreturn payload;","outputs":1,"noerr":0,"x":251,"y":276,"wires":[["342ad05e.cbd53"]]},{"id":"23467d6a.dcb982","type":"debug","z":"b83a61b3.47c5a","name":"","active":false,"console":"false","complete":"true","x":962.25,"y":261.75,"wires":[]},{"id":"50e0c648.af1f38","type":"function","z":"b83a61b3.47c5a","name":"Get SetPoint Value","func":"msg.payload = msg.svalue1\nreturn msg;","outputs":1,"noerr":0,"x":630.194465637207,"y":275.0833168029785,"wires":[["a97981c8.56868"]]},{"id":"342ad05e.cbd53","type":"switch","z":"b83a61b3.47c5a","name":"filter Setpoint IDX","property":"idx","rules":[{"t":"eq","v":"160"}],"checkall":"true","outputs":1,"x":429.4444274902344,"y":275.5555419921875,"wires":[["50e0c648.af1f38"]]},{"id":"a97981c8.56868","type":"exec","z":"b83a61b3.47c5a","command":"/opt/nefit/nefit-set","addpay":true,"append":"","useSpawn":"","name":"Nefit Set Temp","x":820.0000114440918,"y":274.75000381469727,"wires":[["23467d6a.dcb982"],[],[]]},{"id":"6440aca2.9bbf54","type":"comment","z":"b83a61b3.47c5a","name":"Read changes from Domoticz and send to Easy","info":"","x":186,"y":239,"wires":[]},{"id":"6ebefa6b.914104","type":"function","z":"b83a61b3.47c5a","name":"Domoticz MQTT","func":"// Configuration\nconst IDX_SetPoint = 160;\nconst IDX_RoomTemp = 161;\nconst IDX_Pressure = 162;\nconst IDX_Indicator = 163;\n\nvar NefitJSON = JSON.parse(msg.payload);\nvar domoticz_msg = {};\ndomoticz_msg.topic = \"domoticz/in\";\ndomoticz_msg.payload = {};\n\nif (msg.topic == 'nefit-update')  {\n    domoticz_msg.payload.idx = IDX_RoomTemp;\n    domoticz_msg.payload.nvalue = 0;\n    domoticz_msg.payload.svalue = \"\" + NefitJSON['in house temp'];\n}\nif (msg.topic == 'nefit-pressure')  {\n    domoticz_msg.payload.idx = IDX_Pressure;\n    domoticz_msg.payload.nvalue = 0;\n    domoticz_msg.payload.svalue = \"\" + NefitJSON['pressure'];\n}\n\nreturn domoticz_msg;","outputs":1,"noerr":0,"x":641.5,"y":133.5,"wires":[["5bc7035e.a438fc","3876c9bf.c78936"]]},{"id":"5bc7035e.a438fc","type":"mqtt out","z":"b83a61b3.47c5a","name":"Domoticz MQTT","topic":"","qos":"","retain":"","broker":"22a46350.4b5c8c","x":833.25,"y":95.25,"wires":[]},{"id":"2f2db332.d0d24c","type":"exec","z":"b83a61b3.47c5a","command":"/opt/nefit/nefit-pressure","addpay":false,"append":"","useSpawn":"","name":"Nefit Easy Pressure","x":433.00000762939453,"y":177,"wires":[["6ebefa6b.914104"],[],[]]},{"id":"baf3b005.450c5","type":"inject","z":"b83a61b3.47c5a","name":"","topic":"nefit-pressure","payload":"","payloadType":"date","repeat":"300","crontab":"","once":false,"x":184.00001525878906,"y":177,"wires":[["2f2db332.d0d24c"]]},{"id":"2b4dca2.fd4b236","type":"comment","z":"b83a61b3.47c5a","name":"Publish data from Nefit Easy Client to Domoticz","info":"","x":179,"y":70,"wires":[]}]
It now uses MQTT to publish the messages and will also retrieve the pressure.
You also need an additional script
/opt/nefit/nefit-pressure

Code: Select all

export NEFIT_SERIAL_NUMBER='xxxx'
export NEFIT_ACCESS_KEY='xxxx'
export NEFIT_PASSWORD='xxxx'
easy pressure