Rules not working and "how to send data to 3rd party"
Moderators: grovkillen, Stuntteam, TD-er
-
- New user
- Posts: 4
- Joined: 06 Nov 2018, 10:44
Rules not working and "how to send data to 3rd party"
Firstly, a new comer to this forum. The posts look really useful and I enjoy reading them.
I have a Sonoff TH16 that I've flashed with "ESP_Easy_mega-20181105_normal_ESP8266_1024.bin".
Attached is a temperature/humidity gauge "Environment - DHT11/12/22 SONOFF2301/7021" .
On the single relay I have a 2kW fan heater.
The temperature and humidity are correctly displayed in the "devices" section.
I can happy turn the heater on/off from either the tools command "GPIO,12,[0,1]" or via a web request "http://sonoff_ip_address/control?cmd=gpio,12,0"
I ideally want to be able to sent the temperature being measured by the Sonoff to my Loxone home automation system. This is my existing control for my lighting, heating, etc. The Loxone can then make decisions about what temperature the office should be and control the heater.
My initial thought was to use a rule with SendToHTTP i.e.
on OfficeTemp#Temp do
SendToHTTP userId:passwd@loxone_ip_address,80,/dev/sps/io/OfficeTemp/[OfficeTemp#Temp]
SendToHTTP laptop_ip_address,8001,/control?cmd=7dt,[OfficeTemp#Temp]
endon
where userId, passwd, loxone_ip_address and laptop_ip_address would be the actual account, password and ip address of my Loxone box. OfficeTemp is the name I've given to the output of the gauge in the devices section . I've checked in the log and can see I must be going something correct as I see this
60325492: DHT : Temperature: 26.70
60325492: DHT : Humidity: 49.00
60325495: EVENT: OfficeTemp#Temp=26.70
60325516: ACT : SendToHTTP xxx:yyy@zzz,80,/dev/sps/io/OfficeTemp/26.7
60325533: ACT : SendToHTTP vvvv,8001,/control?cmd=7dt,26.7
60325553: EVENT: OfficeTemp#Humidity=49.00
Where xxx, yyy,zzz and vvvv are all correct. and the number is the current temperature being displayed on my devices. My problem is I can not tell what is actually being sent to my Loxone box. If I use "Postman" and "post" a command like this
http://userId:passwd@loxone_ip_address/dev/sps/io/OfficeTemp/23
My Loxone box does indeed show 23 in the OfficeTemp. However, this SendToHTTP is not having the same affect and no value is being received.
I added the second SendToHTTP call to my laptop so I could see what was coming in via wireshark. There doesn't appear to be a http request in here at all (filtered to only show ip from sonoff_ip_address.
So, to have a temporary solution to this I'd thought I could use a rule to turn the heater on and off when some hard-coded limits were reached.
So, another rule
on [OfficeTemp#Temp] < 18.0 do
GPIO,12,1
endon
and a 3rd rule
on [OfficeTemp#Temp] > 20.0 do
GPIO,12,0
endon
These rules do not appear to trigger at all no matter how hot or cold it gets.
I'm sure this is newbie stupidity but I can't see it.
I have a Sonoff TH16 that I've flashed with "ESP_Easy_mega-20181105_normal_ESP8266_1024.bin".
Attached is a temperature/humidity gauge "Environment - DHT11/12/22 SONOFF2301/7021" .
On the single relay I have a 2kW fan heater.
The temperature and humidity are correctly displayed in the "devices" section.
I can happy turn the heater on/off from either the tools command "GPIO,12,[0,1]" or via a web request "http://sonoff_ip_address/control?cmd=gpio,12,0"
I ideally want to be able to sent the temperature being measured by the Sonoff to my Loxone home automation system. This is my existing control for my lighting, heating, etc. The Loxone can then make decisions about what temperature the office should be and control the heater.
My initial thought was to use a rule with SendToHTTP i.e.
on OfficeTemp#Temp do
SendToHTTP userId:passwd@loxone_ip_address,80,/dev/sps/io/OfficeTemp/[OfficeTemp#Temp]
SendToHTTP laptop_ip_address,8001,/control?cmd=7dt,[OfficeTemp#Temp]
endon
where userId, passwd, loxone_ip_address and laptop_ip_address would be the actual account, password and ip address of my Loxone box. OfficeTemp is the name I've given to the output of the gauge in the devices section . I've checked in the log and can see I must be going something correct as I see this
60325492: DHT : Temperature: 26.70
60325492: DHT : Humidity: 49.00
60325495: EVENT: OfficeTemp#Temp=26.70
60325516: ACT : SendToHTTP xxx:yyy@zzz,80,/dev/sps/io/OfficeTemp/26.7
60325533: ACT : SendToHTTP vvvv,8001,/control?cmd=7dt,26.7
60325553: EVENT: OfficeTemp#Humidity=49.00
Where xxx, yyy,zzz and vvvv are all correct. and the number is the current temperature being displayed on my devices. My problem is I can not tell what is actually being sent to my Loxone box. If I use "Postman" and "post" a command like this
http://userId:passwd@loxone_ip_address/dev/sps/io/OfficeTemp/23
My Loxone box does indeed show 23 in the OfficeTemp. However, this SendToHTTP is not having the same affect and no value is being received.
I added the second SendToHTTP call to my laptop so I could see what was coming in via wireshark. There doesn't appear to be a http request in here at all (filtered to only show ip from sonoff_ip_address.
So, to have a temporary solution to this I'd thought I could use a rule to turn the heater on and off when some hard-coded limits were reached.
So, another rule
on [OfficeTemp#Temp] < 18.0 do
GPIO,12,1
endon
and a 3rd rule
on [OfficeTemp#Temp] > 20.0 do
GPIO,12,0
endon
These rules do not appear to trigger at all no matter how hot or cold it gets.
I'm sure this is newbie stupidity but I can't see it.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Rules not working and "how to send data to 3rd party"
First of all. THANKS for being a newcomer
I'm not really sure that giving the password/user id is part of the scope for the SendHTTP command. But the the later code is incorrect. Please read the tutorial guides here: https://www.letscontrolit.com/wiki/inde ... rial_Rules
In short, this should be the correct rule for internally controlling the fan:
But you should look into the regulator plugin and see if that one fits your needs.
I'm not really sure that giving the password/user id is part of the scope for the SendHTTP command. But the the later code is incorrect. Please read the tutorial guides here: https://www.letscontrolit.com/wiki/inde ... rial_Rules
In short, this should be the correct rule for internally controlling the fan:
Code: Select all
on OfficeTemp#Temp do
if [OfficeTemp#Temp] < 18.0
GPIO,12,1
endif
if [OfficeTemp#Temp] > 20.0
GPIO,12,0
endif
endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
-
- New user
- Posts: 4
- Joined: 06 Nov 2018, 10:44
Re: Rules not working and "how to send data to 3rd party"
Thanks grovkillen for the rules correction and the use of "Regulator plugin". That appears to work as my office is no longer cold! It tool a little while to realise that plugins are reached through the "devices" section and are some of the entries in the pull-down - Wiki talks about plugins but not where to find them in the GUI.
There is an option in the Regulator plugin to talk to a controller. If I select a generic HTTP controller and set one up I still can't get any notification to my Loxone box. I think people have asked on this forum before but I haven't seen an actual answer. So, my outstanding question is: How to send data via http to a 3rd party:
I need to send a message that looks like this:
http://userId:passwd@loxone_ip_address/dev/sps/io/OfficeTemp/a_number
I know this works, as using a program like postman does indeed show the correct number in my Loxone screen for OfficeTemp
There is an option in the Regulator plugin to talk to a controller. If I select a generic HTTP controller and set one up I still can't get any notification to my Loxone box. I think people have asked on this forum before but I haven't seen an actual answer. So, my outstanding question is: How to send data via http to a 3rd party:
I need to send a message that looks like this:
http://userId:passwd@loxone_ip_address/dev/sps/io/OfficeTemp/a_number
I know this works, as using a program like postman does indeed show the correct number in my Loxone screen for OfficeTemp
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Rules not working and "how to send data to 3rd party"
I'm not up to date with the generic http controller. Must look into that.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: Rules not working and "how to send data to 3rd party"
Being able to pass user_name / password in the SendtoHttp will make a nice "MQTT to HTTP gateway" in the Rules, for devices within the network that do not support MQTTgrovkillen wrote: ↑09 Nov 2018, 17:09 I'm not up to date with the generic http controller. Must look into that.
-D
-D
Re: Rules not working and "how to send data to 3rd party"
I currently assume we are still unable to use SendtoHttp when Domoticz requires a username and a password via RULES?iron wrote: ↑10 Jan 2019, 11:17Being able to pass user_name / password in the SendtoHttp will make a nice "MQTT to HTTP gateway" in the Rules, for devices within the network that do not support MQTTgrovkillen wrote: ↑09 Nov 2018, 17:09 I'm not up to date with the generic http controller. Must look into that.
-D
I can cheat ofcourse by creating Generic Dummy Sensors.... and store the values in them.
However this seems to be impossible for an air quality sensor.
Code: Select all
/json.htm?type=command¶m=udevice&idx=IDX&nvalue=PPM
/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP
Any ideas what I should select in: Simulate Data Type
Re: Rules not working and "how to send data to 3rd party"
I am using password for Domoticz for connections from outside Internet ( WLAN ).
But setting it to no required password from my local network. ( LAN )
And what problem is with airsensor?
I think
Must work.
( I check it now with my Domoticz and it works )
But setting it to no required password from my local network. ( LAN )
And what problem is with airsensor?
I think
Code: Select all
/json.htm?type=command¶m=udevice&idx=IDX&nvalue=[ your_dummy_variable_for PPM ]
( I check it now with my Domoticz and it works )
Re: Rules not working and "how to send data to 3rd party"
Authorization
When using some method other than a browser to connect to Domoticz it may be necessary to do Authorization differently. Authorization over HTTP is done by setting the "Authorization" HTTP request header when sending the request to Domoticz. The value of this header is a base64 encoded string of the username and password. When connecting to Domoticz using a browser and the URL method above the browser sets the appropriate header. When creating your own app or script this is not always done for you.
First the username and password are combined into one string "username:password"
This string is encoded using the RFC2045-MIME version of base64
The authorization method and a space i.e. "Basic " is then put before the encoded string.
This results in a header in the following format:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
How the header is send differs per programming language. Check the documentation of the language of your choice on how to set http request headers.
This method works with both the Basic-Auth and Login page options.
Authorization with parameters
An other way to set username and password when calling the API is :
http://domoticz-ip<:port>/json.htm?username=MkE=&password=OVM=&api-call
MkE= is the base64 encoded username ('2A' in this example)
OVM= is the base64 encoded password ('9S' in this example)
Users
When you use an user and password in this api, the user must have "user" or "admin" rights.
He also must have the right to access the device (see 'SetDevices' in users page).
Base64 encode
To encode a string using base64 you could use : codebeautify.org/base64-encode
Response
All responses include a status which is either OK on success or ERR on failure
https://www.domoticz.com/wiki/Domoticz_ ... horization
When using some method other than a browser to connect to Domoticz it may be necessary to do Authorization differently. Authorization over HTTP is done by setting the "Authorization" HTTP request header when sending the request to Domoticz. The value of this header is a base64 encoded string of the username and password. When connecting to Domoticz using a browser and the URL method above the browser sets the appropriate header. When creating your own app or script this is not always done for you.
First the username and password are combined into one string "username:password"
This string is encoded using the RFC2045-MIME version of base64
The authorization method and a space i.e. "Basic " is then put before the encoded string.
This results in a header in the following format:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
How the header is send differs per programming language. Check the documentation of the language of your choice on how to set http request headers.
This method works with both the Basic-Auth and Login page options.
Authorization with parameters
An other way to set username and password when calling the API is :
http://domoticz-ip<:port>/json.htm?username=MkE=&password=OVM=&api-call
MkE= is the base64 encoded username ('2A' in this example)
OVM= is the base64 encoded password ('9S' in this example)
Users
When you use an user and password in this api, the user must have "user" or "admin" rights.
He also must have the right to access the device (see 'SetDevices' in users page).
Base64 encode
To encode a string using base64 you could use : codebeautify.org/base64-encode
Response
All responses include a status which is either OK on success or ERR on failure
https://www.domoticz.com/wiki/Domoticz_ ... horization
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests