Page 2 of 8

Re: Python script for Netatmo weather station

Posted: Saturday 23 August 2014 18:18
by fwehrle
Hi cp9999,

Sorry for late response too.
All is working nice.
Only one thing : the barometer (type 83) isn't exist anymore in Domoticz (don't know why).
I create a 243/9 type/subtype device that can store value in Bar (pressure). But it's not a weather sensor, but a generic measure sensor.
My question : is it possible that you modify the script to store temp, humidity and pressure in one combinated weather device (type 84/1) in domoticz?
(And for external Temp/humidity of aditionnal module, we can do the same and store temp/humidity in a combinated temp/humidity domoticz sensor)

What do you think about it?

Re: Python script for Netatmo weather station

Posted: Thursday 28 August 2014 19:06
by mikl10
Hi everybody,
I just start with home automation, i bought a raspberry B+ and i have installed domoticz.
i'm trying to connect my netatmo to my domoticz interface.
Can you tell me if is possible to see noise information send by netatmo?what is her dev_type and dev_subtype?
thank you

Re: Python script for Netatmo weather station

Posted: Thursday 28 August 2014 20:30
by fwehrle
No, there is not yet noise device in domoticz.. :(
But if someone with Python skills want to add a domoticz user variable... :)

You can copy the beginning of each line in xml setting file :

<device data_type="Temperature" domoticz_dev_id="90001" domoticz_dev_subtype="10" domoticz_dev_type="80" ...
<device data_type="Co2" domoticz_dev_id="90004" domoticz_dev_subtype="0" domoticz_dev_type="249" ...
<device data_type="Humidity" domoticz_dev_id="90002" domoticz_dev_subtype="0" domoticz_dev_type="81" ...
<device data_type="Noise" domoticz_dev_id="" domoticz_dev_subtype="" domoticz_dev_type="" ...
<device data_type="Pressure" domoticz_dev_id="90013" domoticz_dev_subtype="9" domoticz_dev_type="243" ...
<device data_type="Temperature" domoticz_dev_id="90011" domoticz_dev_subtype="10" domoticz_dev_type="80" ...
<device data_type="Humidity" domoticz_dev_id="90012" domoticz_dev_subtype="0" domoticz_dev_type="81" ...

Re: Python script for Netatmo weather station

Posted: Thursday 28 August 2014 21:03
by mikl10
ok thank you for your help fwehrie.
I'm looking for a list with all dev_type and subtype, do you know if that exist?
I'm looking in this forum and the wiki but I don't find.

Re: Python script for Netatmo weather station

Posted: Thursday 28 August 2014 21:10
by fwehrle
You're welcome.
Here is all what I found : http://www.domoticz.com/wiki/Domoticz_A ... ual_Sensor

Re: Python script for Netatmo weather station

Posted: Sunday 14 September 2014 17:25
by mikl10
I have retored domoticz and now I can't run netatmo.py

I have this message:
pi@domoticzpi ~/domoticz/scripts $ python ./netatmo.py
-bash: python: command not found

Please,anybody can help me?

EDIT:
finally I had to reinstall python, and everything is back ok

Re: Python script for Netatmo weather station

Posted: Wednesday 08 October 2014 8:44
by wifsimster
Hi,

I've a little problem with the scrip execution :

Code: Select all

Traceback (most recent call last):
  File "netatmo.py", line 530, in <module>
    main()
  File "netatmo.py", line 524, in main
    token = GetToken()
  File "netatmo.py", line 228, in GetToken
    token = LoadToken()
  File "netatmo.py", line 224, in LoadToken
    return RequestToken()
  File "netatmo.py", line 199, in RequestToken
    return CreateToken(json_data)
  File "netatmo.py", line 162, in CreateToken
    newtoken.set(TOKEN_ATTR_ACCESS_TOKEN, json_decoded[TOKEN_ATTR_ACCESS_TOKEN])
KeyError: 'access_token'
I've tried Python 2 and 3 but this is not what cause the problem...

Anyone with this problem on access_token key ?

Re: Python script for Netatmo weather station

Posted: Saturday 01 November 2014 23:37
by krazny
wifsimster wrote:Hi,

I've a little problem with the scrip execution :

Code: Select all

Traceback (most recent call last):
  File "netatmo.py", line 530, in <module>
    main()
  File "netatmo.py", line 524, in main
    token = GetToken()
  File "netatmo.py", line 228, in GetToken
    token = LoadToken()
  File "netatmo.py", line 224, in LoadToken
    return RequestToken()
  File "netatmo.py", line 199, in RequestToken
    return CreateToken(json_data)
  File "netatmo.py", line 162, in CreateToken
    newtoken.set(TOKEN_ATTR_ACCESS_TOKEN, json_decoded[TOKEN_ATTR_ACCESS_TOKEN])
KeyError: 'access_token'
I've tried Python 2 and 3 but this is not what cause the problem...

Anyone with this problem on access_token key ?
Did you create an account @ Netatmo website (https://dev.netatmo.com/) and added the token ID's to the settings file?

Re: Python script for Netatmo weather station

Posted: Saturday 01 November 2014 23:42
by krazny
I have a little problem of my own;

When I run the script the "Netatmo_Settings.xml" file isn't updated with the device ID's.

My steps;
1. Installed python (sudo apt-get install python)
2. Enabled the Netatmo API (https://dev.netatmo.com/dev/)
3. Created the netatmo.py and the netatmo_settings.xml file and enabled execution rights. (/home/pi/domoticz/scripts)
4. Added the Netatmo Token and ID's to the netatmo_settings.xml file.
5. run the netatmo.py script. (python netatmo.py)

edit:
I get the error below:
pi@domoticzpi ~/domoticz/scripts $ python netatmo.py
File "netatmo.py", line 504
Log("Error in HandleDevices")
^
IndentationError: unindent does not match any outer indentation level
As far as I can understand the Netatmo_Settings.xml file should now contain the Device ID's of my netatmo hardware?
It doesnt...

What am I doing wrong?
The tutorial says it won't add the device ID's when your token etc aren't correct. They are 100% correct.
I'm stuck... :(

Re: Python script for Netatmo weather station

Posted: Wednesday 26 November 2014 15:25
by Hertog
Hi,

I have edited the python code so that it now can work with the combined Temperature/Humidity/Barometer, and Temperature/Humidity sensor type.
The netatmo.py and netatmo_settings.xml are in the following zip file.
The settings file is included as an exampe, the netatmo.py will auto generate it, but it needs some editing before it will work. Procedure is the same as in the first post. The Domoticz_dev_type should be copied as it is in the included xml file.

https://www.dropbox.com/s/71jvdm7k7ufx2 ... o.zip?dl=0

Regards,

Hertog

Re: Python script for Netatmo weather station

Posted: Wednesday 26 November 2014 16:06
by fwehrle
Nice,

Thank you. I'll try it asap.
Do you think it's possible to modify the python script to add Noise Level ? Maybe in a variable or something else...

Re: Python script for Netatmo weather station

Posted: Wednesday 26 November 2014 16:14
by Hertog
I'm kind of stuck with the types that Domoticz supplies itself, and noise isn't one of them. The obious way to implement the full range of possibilities (and make the configuration easier) would be to implement the netatmo natively to domoticz, but since my C++-foo isn't that strong, I wouldn't hold my breath for that ;)

One thing I would like to implement in the current python version is the battery level and signal strength. The data is all there, it's just a matter of appending them to the curl call to domoticz. As soon as I see a way to get the noise data into domoticz I'll add it.

edit: forecasts are also on the todo list. This data is also provided by netatmo, why not use it :)

Re: Python script for Netatmo weather station

Posted: Wednesday 26 November 2014 18:39
by fwehrle
Good ideas.
We can also ask for the adding of a dummy sensor for noise... :)

Re: Python script for Netatmo weather station

Posted: Thursday 27 November 2014 11:34
by box18
All the steps
0. Download the netatmo.py and the netatmo_settings.xml from http://www.domoticz.com/forum/download/file.php?id=785

1. Installed python on Rpi

Code: Select all

sudo apt-get install python
2. Enabled the Netatmo API https://dev.netatmo.com/dev/

3. Create one Virtual hardware device in domoticz and use that hardware id for the Netatmo devices
Add 192.168.X.X:8080/json.htm?type=command&param=addhardware&htype=15&port=1&name=NetAtmo&enabled=true
Check ID 192.168.X.X:8080/json.htm?type=hardware
Check.jpg
Check.jpg (39.89 KiB) Viewed 11773 times
4. Edit netatmo_settings.xml with Notepad++
YOUR_CLIENT_ID
YOUR_CLIENT_SECRET
YOUR_PASSWORD
YOUR_USERNAME

Check ID 192.168.X.X:8080/json.htm?type=hardware
Check.jpg
Check.jpg (39.89 KiB) Viewed 11773 times
hardware_id="XXX" - my case "2"
url="http://127.0.0.1:8080"

5. Copy by WINSCP to Rpi (domoticz/scripts) or another solution the files netatmo.py and the netatmo_settings.xml

6. Enabled execution rights.

Code: Select all

cd domoticz/scripts
and

Code: Select all

chmod +x ./netatmo.py
7. Now run the script once.

Code: Select all

python netatmo.py
9. Edit netatmo_settings.xml

Code: Select all

nano netatmo_settings.xml
For the domoticz_dev_id="" we can add any number (XXXX) that is not yet taken in Domoticz - Devices 192.168.X.X:8080/#/Devices

Code: Select all

<device data_type="Temperature" domoticz_dev_id="90001" domoticz_dev_subtype="10" domoticz_dev_type="80" ...
	<device data_type="Co2" domoticz_dev_id="90002" domoticz_dev_subtype="0" domoticz_dev_type="249" ...
	<device data_type="Humidity" domoticz_dev_id="90003" domoticz_dev_subtype="0" domoticz_dev_type="81" ...
	<device data_type="Noise" domoticz_dev_id="" domoticz_dev_subtype="" domoticz_dev_type="" ...
	<device data_type="Pressure" domoticz_dev_id="90004" domoticz_dev_subtype="9" domoticz_dev_type="243" ...
	<device data_type="Temperature" domoticz_dev_id="90005" domoticz_dev_subtype="10" domoticz_dev_type="80" ...
	<device data_type="Humidity" domoticz_dev_id="90006" domoticz_dev_subtype="0" domoticz_dev_type="81" ...
10. Run after 5 minutes

Code: Select all

cd
and

Code: Select all

python /home/pi/domoticz/scripts/netatmo.py
11. Check in Domoticz - Devices 192.168.X.X:8080/#/Devices
Domoticz.jpg
Domoticz.jpg (77.57 KiB) Viewed 11773 times
For the Humidity sensors the ID is changed but keep it like that.

12. Add in CRON

Code: Select all

sudo crontab -e
#ADD

Code: Select all

*/5 * * * * python /home/pi/domoticz/scripts/netatmo.py &

Maybe you need this also.

Code: Select all

sudo service domoticz.sh start

Re: Python script for Netatmo weather station

Posted: Thursday 27 November 2014 12:07
by box18
Virtual.jpg
Virtual.jpg (44.9 KiB) Viewed 11771 times
Is it possible by script to change the name of "Unknown" to "Netatmo"like in image?

COOO it is created by virtual hardware and then Air quality.

Re: Python script for Netatmo weather station

Posted: Thursday 27 November 2014 13:20
by box18
Hertog wrote:I'm kind of stuck with the types that Domoticz supplies itself, and noise isn't one of them. The obious way to implement the full range of possibilities (and make the configuration easier) would be to implement the netatmo natively to domoticz, but since my C++-foo isn't that strong, I wouldn't hold my breath for that ;)

One thing I would like to implement in the current python version is the battery level and signal strength. The data is all there, it's just a matter of appending them to the curl call to domoticz. As soon as I see a way to get the noise data into domoticz I'll add it.

edit: forecasts are also on the todo list. This data is also provided by netatmo, why not use it :)

Will be nice!

Re: Python script for Netatmo weather station

Posted: Thursday 27 November 2014 13:32
by Hertog
box18 wrote:
Virtual.jpg
Is it possible by script to change the name of "Unknown" to "Netatmo"like in image?

COOO it is created by virtual hardware and then Air quality.
I'm afraid that is not possible without changing domoticz itself, not sure though, I'll have a look through the C++ code.

Re: Python script for Netatmo weather station

Posted: Monday 01 December 2014 9:23
by box18
Hi Hertog,

How it is the stage for battery level, signal strength. noise sensor, forecasts, etc from Netatmo? That will be a great great idea... We can talk with Domoticz to add it in Hardware...

box18 wrote:
Hertog wrote:I'm kind of stuck with the types that Domoticz supplies itself, and noise isn't one of them. The obious way to implement the full range of possibilities (and make the configuration easier) would be to implement the netatmo natively to domoticz, but since my C++-foo isn't that strong, I wouldn't hold my breath for that ;)

One thing I would like to implement in the current python version is the battery level and signal strength. The data is all there, it's just a matter of appending them to the curl call to domoticz. As soon as I see a way to get the noise data into domoticz I'll add it.

edit: forecasts are also on the todo list. This data is also provided by netatmo, why not use it :)

Will be nice!

Re: Python script for Netatmo weather station

Posted: Tuesday 02 December 2014 9:51
by box18
Hello,

Who can help me to add in the Domoticz the absolute humidity (HS). After that will be easy to compare the quantity of water in the air exterior and interior and when it's the best time to open the windows...

My idea is like that:
I.Because there is already a nice an powerful script to take the data from Netatmo server, we can calculate the absolute humidity by taken the temperature, relative humidity, pressure:
1. The calculation of Psat = EXP(23,3265-(3802,7/(Temp_C+273,18))-(472,68/(Temp_C+273,18))^2)
2. The absolute humidity HS=(0,622*Psat*HR)/(PA-Psat*HR)*1000
Where:
PA = pressure [* 100] convert in Pa
RH = Relative Humidity [%] Ok
Psat = pressure of saturation [Pa]
Temp_C = Temperature [C]
HS= absolute humidity [g of water / Kg air]

II. Create some dummy virtual sensors and update them by python script from the results of our calculation. (HS of each rooms and exterior sensor).

P.S. ( If you want to know the quantity of water in the air of your room, you need to * by volume of the room (house)) * ~1,205722 kg/m3 (air mass at 20 C)
http://www.cactus2000.de/fr/unit/masshum.shtml

So, I need help in:
1. Take the variables Temp(ext & int), RH(ext & int), Pa in the script netatmo.py
2. Add the formulas
3. Create and update the HS virtual sensors in Domoticz.

I think the best way is to be add in the script netatmo.py to be done in the same time that it take the data.
One problem can be in Domoticz virtual sensor to add the unit. From the wiki site it support:
1 Pressure (Bar) 0.0 nvalue=BAR (TBC)
2 Percentage 0.0 nvalue=PCT (TBC)
80 TEMP 0.0 svalue=TEMP
81 HUM 1 nvalue=HUM svalue=1 to 3
82 TEMP_HUM 0.0;50;1 svalue=TEMP;HUM;HUM_STATUS
84 TEMP_HUM_BARO 0.0;50;1;1010;1 svalue=TEMP;HUM;HUM_STATUS;BARO;BARO_FCST
85 RAIN 0;0 svalue=RAIN;Rain in mm/h
86 WIND 0;N;0;0;0;0 svalue=WIN_SPD;WIND_DIR;?;?;?;?
87 UV 0;0 svalue= (TBC)
113 RFXMeter 0 Can have several values, another order has to be sent to set the sub type:
type 2 Counter: svalue=COUNTER
type 3 Water: svalue=VOLUME
type 1 Gas:
type 0 Energy:
90 ENERGY 0;0.0 svalue=POWER;ENERGY
249 TypeAirQuality 0 nvalue=PPM
Maybe we can use 81 with 10 for decimals.

Re: Python script for Netatmo weather station

Posted: Friday 12 December 2014 16:55
by box18
I did it but Hum_out it is taken Humidity 96 % so will be an error

What are the jq comands or another command to take from the string "Humidity 96% the value 96....????
Same for Pa 1008.3 Pa and I need 1008.3 ????

If ai put these values manualy all are ok, the virtual sensor SetPoint are update
12-12-2014 16-53-46.jpg
12-12-2014 16-53-46.jpg (63.42 KiB) Viewed 11628 times

Code: Select all

#!/bin/bash

# Take the data from Domoticz 
Temp_out=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=8" 2>/dev/null | jq -r .result[]."Temp"`
Temp_int=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=9" 2>/dev/null | jq -r .result[]."Temp"`

Hum_out=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=7" 2>/dev/null | jq -r .result[]."Data"`
Hum_int=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=10" 2>/dev/null | jq -r .result[]."Data"`

Pa=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=11" 2>/dev/null | jq -r .result[]."Data"`

#Calculation 
#1. The calculation of Psat = EXP(23,3265-(3802,7/(Temp_C+273,18))-(472,68/(Temp_C+273,18))^2) [Pa]
#2. The absolute humidity HS=(0,622*Psat*HR)/(PA-Psat*HR)*1000 [geau/kg air sec]
#3. L'eau chambre volume [m3] * mass l'air [kg/m3] * HS[g/kg] = [g]

Psat_out=`echo "e(23.3265-(3802.7/($Temp_out+273.18))-(472.68/($Temp_out+273.18))^2)" | bc -l`
HS_out=`echo "(0.622*$Psat_out*$Hum_out/100)/($Pa*100-$Psat_out*$Hum_out/100)*1000" | bc -l`

Psat_int=`echo "e(23.3265-(3802.7/($Temp_int+273.18))-(472.68/($Temp_int+273.18))^2)" | bc -l`
HS_int=`echo "(0.622*$Psat_int*$Hum_int/100)/($Pa*100-$Psat_int*$Hum_int/100)*1000" | bc -l`

#Add the calcutation to virtual sensor
A1=`curl "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=21&nvalue=0&svalue=$HS_out"` 
A1=`curl "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=24&nvalue=0&svalue=$HS_int"`