How set uservar in Domotucz

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

How set uservar in Domotucz

#1 Post by BartSr » 19 Dec 2020, 19:44

Hi!

I can set a uservar from an Arduinosketch this way:

client.print("GET /json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=0")

From the Wiki:

/json.htm?type=command&param=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE


Is there a similar way using ESP-Easy?

TIA
-Bart

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How set uservar in Domotucz

#2 Post by Ath » 19 Dec 2020, 20:56

When enabling Rules (Tools/Advanced) you can use the SendToHTTP command from an event handler to send some value to Domoticz.
Many examples available here on the Forum, and in the documentation at https://espeasy.readthedocs.io/en/latest/index.html
/Ton

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#3 Post by BartSr » 20 Dec 2020, 12:39

As the learning curve us high for me : Can you give me a hand pls about the syntax for sending the HTTP command once an gpio configered being input goes high or low?

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How set uservar in Domotucz

#4 Post by Ath » 20 Dec 2020, 13:40

I'm assuming you've been able to enable Rules.

When sending sensor data from ESPEasy to Domoticz, usually it is the easiest to use the Domoticz HTTP or MQTT controllers for that. Just enable one of these in the Controller tab and fill the requirements like ip address and username/password if any.

After that you can select on the devices page a controller that should handle the device data, f.e. like this:
Screenshot - 20-12-2020 , 13_20_20.png
Screenshot - 20-12-2020 , 13_20_20.png (27.91 KiB) Viewed 2995 times
The IDX value you get from Domoticz for the Temperature/Barometer/Humidity dummy device you have to add there (See Domoticz docs for that).

This is also feasible for pulse counters etc.

But if you have 'other' data, or text, to send to Domoticz, then you can send it from the Rules, in this example after receiving a new value for a Dummy Device (Single), defined in ESPEasy with name Variables and value Manual:
Screenshot - 20-12-2020 , 13_25_26.png
Screenshot - 20-12-2020 , 13_25_26.png (17.49 KiB) Viewed 2995 times
When that value changes, an event is fired:

Code: Select all

on Variables#Manual do
  SendToHTTP,DOMOTICZ_IP,DOMOTICZ_PORT,/json.htm?type=command&param=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=Count%20is%20[Variables#Manual]
endon
You will need to replace DOMOTICZ_IP and DOMOTICZ_PORT with the correct values, just like the vname and vtype stuff you provided yourself already.
If needed you can add username=??&password=?? (using the Base64'ed values of your Domoticz's username and password) between ? and type.
If the vvalue part needs to have spaces, f.e. when sending to a text device in Domoticz, these spaces (and other special characters like / & ?) need to be url-encoded, so a space becomes %20.
/Ton

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#5 Post by BartSr » 27 Dec 2020, 21:50

Tom,

Thanks a lot.
I ve tried but cannot get the task-settings as in yr example.
Meanwhile I only can select sensors which seems to hold numerics.
Might this be cause by different built?
I'm using 147.

-Bart

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How set uservar in Domotucz

#6 Post by TD-er » 27 Dec 2020, 22:18

Can you check with a more recent build?
https://github.com/letscontrolit/ESPEasy/releases
Just to be sure (when you might want to return to the older version), backup the settings file before updating :)

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How set uservar in Domotucz

#7 Post by Ath » 28 Dec 2020, 09:59

BartSr wrote: 27 Dec 2020, 21:50 Meanwhile I only can select sensors which seems to hold numerics.
The values in ESPEasy are stored as float (numeric) only, and can be converted to specific strings. That is still a restriction, also in the latest build. (Strings need way more (memory)resources than floats, and these resources are quite limited on ESP's, both on the ESP8266 and ESP32 units)

ESPEasy is working toward a release version, so native string support won't be available in the near future, but we have been living with this for years, so, obviously that's not been a real blocker :D
/Ton

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#8 Post by BartSr » 28 Dec 2020, 21:02

I get stuck.
I am following the URL https://github.com/letscontrolit/ESPEasy/releases I clicked on Release mega-20201227 but I cannot find any valid .bin file overthere.
What am I missing?

I clicked on Release mega-20201227 as I expected it to be a link leading to the .bin file.
Than I clicked on the shape with text mega-20201227 which put me in the environment holding many maps with code.
Also in the dist map I couldnot find a valid bin file.

How to further ???

KR
-Bart

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How set uservar in Domotucz

#9 Post by Ath » 28 Dec 2020, 21:37

At the end of each block of Release notes there is an Assets link that can be expanded, where you can find .zip files. The one named ESPEasy_ESP82xx_mega-20201227.zip contains, surprisingly, the ESP8266 and ESP8285 bin files, and ESPEasy_ESP32_mega-20201227.zip contains the ESP32 bin files.

Unpack the zip file into a directory, fire up the ESP.Easy.Flasher.exe, and it should find the COM port your ESP is on, assuming you connected it to your PC. You can select the desired bin file from the combobox (initially it says NONE SELECTED).
The flasher requests Administrator access because it interacts directly with the com-port, and Windows requires admin privileges to do that, unfortunately.

When flashing an ESP8266 in a device like a Sonoff 20 etc. you need to get it into programming mode by connecting GPIO-0 to ground while resetting or powering up, an ESP32 needs to be pressed the Boot and EN buttons (and Boot held pressed) to get there, and a Wemos or NodeMCU can be put into programming mode by wiggling the serials connection, so no special action needs to be taken.
An ESP32 needs to be flashed with a -factory.bin file from the flasher, or with the other .bin (without -factory) when updating via OTA.
/Ton

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#10 Post by BartSr » 28 Dec 2020, 22:24

Thanks a lot for your help.
I'm almost there!
But....
The ESP Easy Flasher reports : No online COM ports found!
Once I tick : Only active ports the correct port shows up saying (COM3) USB-SERIAL CH340 (Port_#0001.Hub_#0007) [offline]
But as it shows offline, for what reason? I cannot flash.
How can I get the com port (USB) active?

BTW which bin-file do you advise compared to the one I used up to now (R147)

THanks!
-Bart

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#11 Post by BartSr » 28 Dec 2020, 22:27

oops
once I restarted the flasher it works!
Thanks
-Bart

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How set uservar in Domotucz

#12 Post by Ath » 29 Dec 2020, 10:53

BartSr wrote: 28 Dec 2020, 22:24 BTW which bin-file do you advise compared to the one I used up to now (R147)
That depends on the plugins you want to use, the most common ones are in the 'normal' builds, but some more exotic, or still in testing mode, can be found in the 'test' builds. If your ESP has 4MB of flash you can safely use a 'test' build, as it also includes all 'normal' plugins.
/Ton

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#13 Post by BartSr » 10 Jan 2021, 19:06

Hi.
Thanks to the received info from the above mentioned forum-members I managed to set a Domoticz uservar based upon a change of a gpio value.
So far so good. But I found that on boot there is no check on status of input gpio which should set the Domoticz uservar accordingly.
What is the correct way to do so?
TIA
-Bart

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How set uservar in Domotucz

#14 Post by Ath » 10 Jan 2021, 20:55

If you've set up a Switch device for the GPIO port, you can send the command 'TaskRun,<tasknr>' for that device to trigger a read at any moment you want, and thus the event for it will also fire. Or check the Send Boot State option for that switch.
If you have not set up a switch device, the 'monitor' command is your friend, that you add to the 'on System#Boot do' event, and generates an event every time the state changes.
/Ton

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#15 Post by BartSr » 11 Jan 2021, 21:32

OK,
I managed to set Domoticz userVar based upon a GPIO change.
But although I expected to have a result for the Domoticz userVar at boot of the NodeMCU it fails .
This is my rule code:


on System#Boot do
Monitor GPIO,12
if [Plugin#GPIO#Pinstate#12]=0
SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=0
endif
if [Plugin#GPIO#Pinstate#12]=1
SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=1
endif


endon

on GPIO#12=0 do
if [Plugin#GPIO#Pinstate#12]=0
SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=0
endif
endon

on GPIO#12=1 do
if [Plugin#GPIO#Pinstate#12]=1
SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=1
endif
endon

What's wrong?

TIA
-Bart

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How set uservar in Domotucz

#16 Post by TD-er » 11 Jan 2021, 21:54

Are you sure the URL is using "vvalue" ?
I thought Domoticz only used "nvalue" (integer) or "svalue" (string).


Also I guess this part can be slightly simpler:

Code: Select all

on System#Boot do
  Monitor GPIO,12
  SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=[Plugin#GPIO#Pinstate#12]
endon
And as always, when in doubt about the actual values, you can also log the values using logentry.

But regardless of making it using a shorter notation as I showed here, that's still not going to work for the simple reason you don't have a network connection at boot.

So it is best to store the pin state in a variable and act on the WiFi#connected event to flush that state.

Code: Select all

on System#Boot do
  Monitor GPIO,12
  let,1,[Plugin#GPIO#Pinstate#12] // Store the pin state in the first variable.
endon

on WiFi#Connected do
  // Send the state to Domoticz.
  SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=[int#1]
endon
This is still no ideal solution, as the pin state may have changed in the mean time.
So why not change it to something like this:

Code: Select all

on System#Boot do
  Monitor GPIO,12
endon

on WiFi#Connected do
  // Send the state to Domoticz.
  SendToHTTP,192.168.68.29,8080,/json.htm?type=command&param=updateuservariable&vname=TraplichtAan&vtype=integer&vvalue=[Plugin#GPIO#Pinstate#12]
endon
N.B. I did not change the "vvalue" as you still need to check the actual syntax in Domoticz to make sure it is correct.

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#17 Post by BartSr » 13 Jan 2021, 22:12

Hi TD-er,

Thanks a lot for teaching me.
Your code does exactly what I liked to achieve.
Very gratefull for the steps with comments you showed.
Meanwhile, as I'm pretty new with the ESP-Easy later then V147 it gives me a better inside how to deal with all possibillities.
I mostly learn new things easier by analysing examples.

Best regards,
-Bart

BartSr
Normal user
Posts: 13
Joined: 27 Sep 2019, 17:45

Re: How set uservar in Domotucz

#18 Post by BartSr » 13 Jan 2021, 22:21

I forgot about the vvalue. That's correct syntax.
See:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
where it says:

User variables
Add a new variable
/json.htm?type=command&param=adduservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE
USERVARIABLENAME with the name of the variable
USERVARIABLETYPE is a digit (0,1,2,3,4) or a string (>= 4.10906) (Integer, Float, String, Date, Time)
0 = Integer, e.g. -1, 1, 0, 2, 10
1 = Float, e.g. -1.1, 1.2, 3.1
2 = String
3 = Date in format DD/MM/YYYY
4 = Time in 24 hr format HH:MM
USERVARIABLEVALUE with the value
All formats are checked by the api, when the variable does not match the required format it is not stored.

-Bart

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How set uservar in Domotucz

#19 Post by TD-er » 14 Jan 2021, 11:52

Hmm good to know.
I will think of how we can extend the Domoticz controllers to support those and maybe add extra types for the Dummy plugin to select it.
Or maybe even automatically detect it.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests