Page 1 of 1

Rules not working and "how to send data to 3rd party"

Posted: 06 Nov 2018, 11:45
by jverdicchio
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.
2018-11-06_1030.png
2018-11-06_1030.png (194.54 KiB) Viewed 5488 times
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.

Re: Rules not working and "how to send data to 3rd party"

Posted: 06 Nov 2018, 11:58
by grovkillen
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:

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
But you should look into the regulator plugin and see if that one fits your needs.

Re: Rules not working and "how to send data to 3rd party"

Posted: 09 Nov 2018, 16:54
by jverdicchio
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

Re: Rules not working and "how to send data to 3rd party"

Posted: 09 Nov 2018, 17:09
by grovkillen
I'm not up to date with the generic http controller. Must look into that.

Re: Rules not working and "how to send data to 3rd party"

Posted: 10 Jan 2019, 11:17
by iron
grovkillen wrote: 09 Nov 2018, 17:09 I'm not up to date with the generic http controller. Must look into that.
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 MQTT

-D

Re: Rules not working and "how to send data to 3rd party"

Posted: 19 Mar 2019, 20:07
by sincze
iron wrote: 10 Jan 2019, 11:17
grovkillen wrote: 09 Nov 2018, 17:09 I'm not up to date with the generic http controller. Must look into that.
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 MQTT

-D
I currently assume we are still unable to use SendtoHttp when Domoticz requires a username and a password via RULES?
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&param=udevice&idx=IDX&nvalue=PPM
/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP
As that one does not have the normal svalue... and only the n value.
Any ideas what I should select in: Simulate Data Type

Re: Rules not working and "how to send data to 3rd party"

Posted: 20 Mar 2019, 23:15
by kimot
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

Code: Select all

/json.htm?type=command&param=udevice&idx=IDX&nvalue=[ your_dummy_variable_for PPM ]
Must work.

( I check it now with my Domoticz and it works )

Re: Rules not working and "how to send data to 3rd party"

Posted: 20 Mar 2019, 23:19
by kimot
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