script to send mqtt message with percentage

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

script to send mqtt message with percentage

Post by megamarco83 »

hi, i'm playing a bit with esp8266 this time using tasmota firmware.
what i would like to implement is a script that read the percentage of sliding of dummy device type: inverted blind with percentage and send the conresponding value to esp.

the mqtt message to send is this one:
cmnd/<devicetopic>/shutterposition<Number> <%>


example
if i have this devices on esp that has name: tamota_blind_1 where i have:
1) blind_kitchen
2) blind_kitchen2
3) blind_kitchen3

and another esp that has name: tasmota_blind_2 where i have:
1) blind_bathroom
2) blind_stairs

and i move the percentage of blind stairs at 25%

the script should send to esp tasmota_blind_2 this message:
cmnd/tasmota_blind_2/shutterposition2 25


of course when the message come from esp to domoticz, domoticz should not react.
the message come from esp to domoticz when some one trigger gpio of esp, or when someone use the web interface of esp, in bothcase the command that comes from esp is:
publish domoticz/in {"idx":154,"nvalue":2,"svalue":"%value%"}
of course esp will adress the correct idx and %value% to set the conresponding blind and percentage.


last thing, should be better to have one "blind_master"
that can controll all blind at same % sending out in parallel all commands: cmnd/<devicetopic>/shutterposition<Number> <%>
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

megamarco83 wrote: Sunday 23 February 2020 23:40 hi, i'm playing a bit with esp8266 this time using tasmota firmware.
what i would like to implement is a script that read the percentage of sliding of dummy device type: inverted blind with percentage and send the conresponding value to esp.

the mqtt message to send is this one:
cmnd/<devicetopic>/shutterposition<Number> <%>


example
if i have this devices on esp that has name: tamota_blind_1 where i have:
1) blind_kitchen
2) blind_kitchen2
3) blind_kitchen3

and another esp that has name: tasmota_blind_2 where i have:
1) blind_bathroom
2) blind_stairs

and i move the percentage of blind stairs at 25%

the script should send to esp tasmota_blind_2 this message:
cmnd/tasmota_blind_2/shutterposition2 25


of course when the message come from esp to domoticz, domoticz should not react.
the message come from esp to domoticz when some one trigger gpio of esp, or when someone use the web interface of esp, in bothcase the command that comes from esp is:
publish domoticz/in {"idx":154,"nvalue":2,"svalue":"%value%"}
of course esp will adress the correct idx and %value% to set the conresponding blind and percentage.


last thing, should be better to have one "blind_master"
that can controll all blind at same % sending out in parallel all commands: cmnd/<devicetopic>/shutterposition<Number> <%>
I'm now using shelly to control blinds, but some time ago I used this with tasmota:

https://github.com/kungknut/Domoticz-MQTT-Translator

You can check: https://www.domoticz.com/forum/viewtopi ... 51&t=25604
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

salvacalatayud wrote: Thursday 27 February 2020 9:08
I'm now using shelly to control blinds, but some time ago I used this with tasmota:

https://github.com/kungknut/Domoticz-MQTT-Translator

You can check: https://www.domoticz.com/forum/viewtopi ... 51&t=25604
hi, thanks for reply.
i install today nodered on raspberry with buster.
i import your script and give my mqtt adrress and domoticz ip:port

then i create inside domoticz uservar type string.
here first question:
i try to control 1st blind so i guess my string should be:
{"MQTT":{"devIdx" : 111,"inTopic" : "publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"}","outTopic" : "cmnd/tasmota_blind_1/shutterposition","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}}
but domoticz say that's can be saved....maybe too long?
if yes, how to manage for example 8 blinds?
i set as comand from domoticz:
cmnd/tasmota_blind_1/shutterposition
after shutterposition should be put a number that is the percentage to reach
example:
cmnd/tasmota_blind_1/shutterposition 22
in this case tasmota will move blind1 at 22%

the comand that tasmota should send to domoticz if i move slide on web page of tasmota should be:
publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"}
will be nodered to taking care about that?

with wall switch how to menage?
for example shutter1 has 2switch: switch1 and switch2
short press of switch1 => trigger 1second relay1
long press of switch1 => trigger relay1 till reach 100%open
short press of switch2 => trigger 1second relay2
long press of switch2 => trigger relay2 till reach 100%close
who will manage that?

i create inside tasmota a rule like this:
rule2 on switch1#state=2 do backlog power1 on;delay 10;power1 off endon on switch1#state=3 do power1 on endon
on switch2#state=2 do backlog power2 on;delay 10;power2 off endon on switch2#state=3 do power2 on endon
on switch3#state=2 do backlog power3 on;delay 10;power3 off endon on switch3#state=3 do power3 on endon
on switch4#state=2 do backlog power4 on;delay 10;power4 off endon on switch4#state=3 do power4 on endon

in this case i trigger the relay and due to do this, tasmota should send something, and nodered should automatically report the percentage in domoticz, without adding nothing else, correct?



anyway just to havse a first try i cut from the uservar string the inTopic
so used the string that i used is:
{"MQTT":{"devIdx" : 111,"inTopic" : "","outTopic" : "cmnd/tasmota_blind_1/shutterposition","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}}
Screenshot_2020-02-27 Domoticz.png
Screenshot_2020-02-27 Domoticz.png (35.02 KiB) Viewed 4732 times
idx28 is the numebr of uservar created for nodered


then i try to slide the dummy device type blind inverted, but nothing happened.


i try to add a debug device to nodered as you can see in the pictures:
Screenshot_2020-02-27 Node-RED 192 168 0 105.png
Screenshot_2020-02-27 Node-RED 192 168 0 105.png (42.57 KiB) Viewed 4732 times
that's are part of the errors.

Code: Select all

27/2/2020, 20:07:12node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
27/2/2020, 20:07:13node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
27/2/2020, 20:07:13node: 834676a2.6a9a88domoticz/out : msg.payload : string[264]
"{↵ "Battery" : 255,↵ "RSSI" : 12,↵ "description" : "",↵ "dtype" : "Light/Switch",↵ "id" : "000140C7",↵ "idx" : 119,↵ "name" : "rele_caldaia_ACS",↵ "nvalue" : 0,↵ "stype" : "Switch",↵ "svalue1" : "0",↵ "switchType" : "On/Off",↵ "unit" : 1↵}↵"
27/2/2020, 20:07:14node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
27/2/2020, 20:07:15node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
27/2/2020, 20:07:16node: 834676a2.6a9a88domoticz/out : msg.payload : string[310]
"{↵ "Battery" : 255,↵ "RSSI" : 9,↵ "description" : "",↵ "dtype" : "Temp + Humidity",↵ "id" : "82153",↵ "idx" : 153,↵ "name" : "Cucina cantina",↵ "nvalue" : 0,↵ "stype" : "THGN122/123/132, THGR122/228/238/268",↵ "svalue1" : "16.50",↵ "svalue2" : "46.8",↵ "svalue3" : "1",↵ "unit" : 1↵}↵"
27/2/2020, 20:07:17node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
27/2/2020, 20:07:18node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

Edited
megamarco83 wrote: Thursday 27 February 2020 20:19
hi, thanks for reply.
i install today nodered on raspberry with buster.
i import your script and give my mqtt adrress and domoticz ip:port

then i create inside domoticz uservar type string.
here first question:
i try to control 1st blind so i guess my string should be:
{"MQTT":{"devIdx" : 111,"inTopic" : "publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"}","outTopic" : "cmnd/tasmota_blind_1/shutterposition","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}}
but domoticz say that's can be saved....maybe too long?
if yes, how to manage for example 8 blinds?
i set as comand from domoticz:
cmnd/tasmota_blind_1/shutterposition
after shutterposition should be put a number that is the percentage to reach
example:
cmnd/tasmota_blind_1/shutterposition 22
in this case tasmota will move blind1 at 22%

the comand that tasmota should send to domoticz if i move slide on web page of tasmota should be:
publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"}
will be nodered to taking care about that?

with wall switch how to menage?
for example shutter1 has 2switch: switch1 and switch2
short press of switch1 => trigger 1second relay1
long press of switch1 => trigger relay1 till reach 100%open
short press of switch2 => trigger 1second relay2
long press of switch2 => trigger relay2 till reach 100%close
who will manage that?

i create inside tasmota a rule like this:
rule2 on switch1#state=2 do backlog power1 on;delay 10;power1 off endon on switch1#state=3 do power1 on endon
on switch2#state=2 do backlog power2 on;delay 10;power2 off endon on switch2#state=3 do power2 on endon
on switch3#state=2 do backlog power3 on;delay 10;power3 off endon on switch3#state=3 do power3 on endon
on switch4#state=2 do backlog power4 on;delay 10;power4 off endon on switch4#state=3 do power4 on endon

in this case i trigger the relay and due to do this, tasmota should send something, and nodered should automatically report the percentage in domoticz, without adding nothing else, correct?



anyway just to havse a first try i cut from the uservar string the inTopic
so used the string that i used is:
{"MQTT":{"devIdx" : 111,"inTopic" : "","outTopic" : "cmnd/tasmota_blind_1/shutterposition","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}}
Screenshot_2020-02-27 Domoticz.png
idx28 is the numebr of uservar created for nodered


then i try to slide the dummy device type blind inverted, but nothing happened.

Out topic is the topic coming from tasmota that should be translated by de node-red flow, in your case "stat/tasmota_blind_1/SHUTTER1"
In topic is the topic that tasmota should recive from domoticz, in your case "cmnd/tasmota_blind_1/shutterposition"

Try this:
{"MQTT":{"devIdx" : 111,"inTopic" : "cmnd/tasmota_blind_1/shutterposition","outTopic" : "stat/tasmota_blind_1/SHUTTER1","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}
You must create a new user variable for each blind, with a diferent idx and topic (only tasmota_blind_1).

In your tasmota you must give the same topic.
Last edited by salvacalatayud on Friday 28 February 2020 13:25, edited 3 times in total.
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

salvacalatayud wrote: Friday 28 February 2020 13:01

In topic is the topic coming from tasmota that should be translated by de node-red flow, in your case "state/tasmota_blind_1/shutterposition"
Out topic is the topic that tasmota should recive from domoticz, in your case "cmnd/tasmota_blind_1/shutterposition"

Try this:
{"MQTT":{"devIdx" : 111,"inTopic" : "state/tasmota_blind_1/shutterposition","outTopic" : "cmnd/tasmota_blind_1/shutterposition","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}

You must create a new user variable for each blind, with a diferent idx and topic.
but the intopic should not something like that:
publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"}
where tasmota send to domoticz the percentage and idx of blid?
why:
state/tasmota_blind_1/shutterposition
???
if from tasmota console i write: state/tasmota_blind_1/shutterposition

the response is:

Code: Select all

13:08:13 CMD: state/tasmota_blind_1/shutterposition
13:08:13 MQT: stat/tasmota_blind/RESULT = {"Shutter1":{"Position":40,"Direction":0},"Shutter2":{"Position":39,"Direction":0}}
13:08:13 MQT: stat/tasmota_blind/RESULT = {"ShutterPosition1":40}
domoticz is able to interpretate this message and move accordingly the slide of percentage?


anyway i also tested your proposal of domoticz uservar:

but if i slide the domoticz slider of dummy device set as inverted blind with percentage nothing happened.




iside nodered i create a debug switch and connect to uservar from domoticz
Screenshot_2020-02-28 Node-RED 192 168 0 105.png
Screenshot_2020-02-28 Node-RED 192 168 0 105.png (63.04 KiB) Viewed 4704 times
this is the log:
it seams that it not read the uservar, possible??

Code: Select all

28/2/2020, 13:05:53node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:05:53node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:05:55node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:05:56node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:05:57node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:05:58node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:05:59node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:00node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:02node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:02node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:03node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:03node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:03node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:03node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:04node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:04node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:07node: Convert to urlfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
28/2/2020, 13:06:07node: Format MQTTfunction : (error)
"TypeError: Cannot read property 'length' of undefined"
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

Sorry, here you have the right user variable:

Try this:
{"MQTT":{"devIdx" : 111,"inTopic" : "cmnd/tasmota_blind_1/shutterposition","outTopic" : "stat/tasmota_blind_1/SHUTTER1","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}

(edited previous post)
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

but stat/tasmota_blind_1/shutter1 doesn't exist:

13:26:08 CMD: stat/tasmota_blind_1/shutter1
13:26:08 MQT: stat/tasmota_blind_1/RESULT = {"Command":"Unknown"}

anyway i try also your last sugestion, but nothing happened.

how i can be sure that nodered read correctly the uservar?
did you see the debug log that i posted?
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

megamarco83 wrote: Friday 28 February 2020 13:27 but stat/tasmota_blind_1/shutter1 doesn't exist:

13:26:08 CMD: stat/tasmota_blind_1/shutter1
13:26:08 MQT: stat/tasmota_blind/RESULT = {"Command":"Unknown"}

anyway i try also your last sugestion, but nothing happened.

how i can be sure that nodered read correctly the uservar?
did you see the debug log that i posted?
in tasmota console, if you send "shutterposition 50" what response do you get?
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

i try shutterposition 50

Code: Select all

13:33:29 CMD: shutterposition 50
13:33:29 SHT: Start in dir 0
13:33:29 MQT: stat/tasmota_blind/RESULT = {"POWER2":"ON"}
13:33:29 MQT: stat/tasmota_blind/POWER2 = ON
13:33:29 MQT: stat/tasmota_blind/RESULT = {"ShutterPosition1":50}
13:33:30 SHT: Shutter1 Real 24900, Start 26700, Stop 15000, Dir -1, Delay 0, Rtc 0.30 [s], Freq 1875
13:33:30 MQT: stat/tasmota_blind/RESULT = {"Shutter1":{"Position":83,"Direction":-1},"Shutter2":{"Position":51,"Direction":0}}
13:33:30 SHT: Shutter1 Real 20400, Start 26700, Stop 15000, Dir -1, Delay 0, Rtc 1.05 [s], Freq 1875
13:33:30 MQT: stat/tasmota_blind/RESULT = {"Shutter1":{"Position":68,"Direction":-1},"Shutter2":{"Position":51,"Direction":0}}
13:33:31 MQT: stat/tasmota_blind/RESULT = {"POWER2":"OFF"}
13:33:31 MQT: stat/tasmota_blind/POWER2 = OFF
13:33:31 SHT: Shutter1 Real 15000, Start 26700, Stop 15000, Dir -1, Delay 0, Rtc 1.95 [s], Freq 1875
13:33:31 MQT: stat/tasmota_blind/SHUTTER1 = 50
13:33:31 MQT: stat/tasmota_blind/RESULT = {"Shutter1":{"Position":50,"Direction":0},"Shutter2":{"Position":51,"Direction":0}}
13:33:31 RUL: SHUTTER1#POSITION performs "publish domoticz/in   {"idx":111,"nvalue":2,"svalue":"50"}"
13:33:31 MQT: domoticz/in =   {"idx":111,"nvalue":2,"svalue":"50"}
13:33:31 RUL: SHUTTER2#POSITION performs "publish domoticz/in   {"idx":154,"nvalue":2,"svalue":"51"}"
13:33:31 MQT: domoticz/in =   {"idx":154,"nvalue":2,"svalue":"51"}
last two raws:

Code: Select all

13:33:31 RUL: SHUTTER1#POSITION performs "publish domoticz/in   {"idx":111,"nvalue":2,"svalue":"50"}"
13:33:31 MQT: domoticz/in =   {"idx":111,"nvalue":2,"svalue":"50"}
13:33:31 RUL: SHUTTER2#POSITION performs "publish domoticz/in   {"idx":154,"nvalue":2,"svalue":"51"}"
are createt bu rule:

Code: Select all

Rule1 ON Shutter1#Position DO publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"} endon ON Shutter2#Position DO publish domoticz/in {"idx":154,"nvalue":2,"svalue":"%value%"} endon
and thanks to my rule1 i'm able to report in domoticz the statud of blind if the command start from ESP.
that's also the reason why i asked why you poso the outTopic as:
outTopic" : "stat/tasmota_blind_1/SHUTTER1
and not as:
publish domoticz/in {"idx":111,"nvalue":2,"svalue":"%value%"}
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

Ok, so you get as response "stat/tasmota_blind/SHUTTER1 = 50"

The problem here is the topic itself. You are sending from domoticz to topic tasmota_blind_1 but in tasmota you are using topic tasmota_blind

The rule is not needed if you use translator.
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

maybe i understand
you are right, sorry

i change the uservar:
{"MQTT":{"devIdx" : 111,"inTopic" : "cmnd/tasmota_blind/shutterposition1","outTopic" : "stat/tasmota_blind/SHUTTER1","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "dimmer"}

using as tocpic
tasmota_blind

i deactivare my rule:
rule1 0

but again no lucky. if i move the blind using tasmota webpage domoticz is not updated.
if i move the slide inside domoticz web page, relays are not triggered and web page of tasmota not updated.

if i have to move the blind1 inside tasmota console i have to write:
cmnd/tasmota_blind/shutterposition1 32

and blind1 will move at 32%

if i move the slide in tasmota in which way domoticz pass the 32 percentage?
inside uservar there is only:
cmnd/tasmota_blind/shutterposition1
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

Can you check by subscribing to your mqtt server what messages are sended?

And also check if in domoticz settings page if you have given rights to ip 127.0.0.1 (or ip where node-red is running) to acces from local network

anyway, I will send you my flow as soon as I get home
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

salvacalatayud wrote: Friday 28 February 2020 14:06 Can you check by subscribing to your mqtt server what messages are sended?
here i need some help....
what i have to do to see what message are sended?
i have raspberry where is installed mqtt
or pc with windows. is it possible to us this to see the mqtt messages?
salvacalatayud wrote: Friday 28 February 2020 14:06 And also check if in domoticz settings page if you have given rights to ip 127.0.0.1 (or ip where node-red is running) to acces from local network[/quote
inside settings web page i have:
local networks without passords: 127.0.0.1;192.168.0.*
my mqtt broker is on raspberry, same raspberry where is installed domoticz
salvacalatayud wrote: Friday 28 February 2020 14:06 anyway, I will send you my flow as soon as I get home
thanks so much!!
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

megamarco83 wrote: Friday 28 February 2020 14:33
salvacalatayud wrote: Friday 28 February 2020 14:06 Can you check by subscribing to your mqtt server what messages are sended?
here i need some help....
what i have to do to see what message are sended?
i have raspberry where is installed mqtt
or pc with windows. is it possible to us this to see the mqtt messages?
I use mac, but look for a mqtt client for windows and check all the topics on your server
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

thanks i find and extension of google chrome: mqttLens
i configure the IP of broker and make a connection.
now it ask me subscrive topic or publish topic.
what i have to enter?
thanks
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

megamarco83 wrote: Friday 28 February 2020 14:49 thanks i find and extension of google chrome: mqttLens
i configure the IP of broker and make a connection.
now it ask me subscrive topic or publish topic.
what i have to enter?
thanks
subscribe to tasmota_blind
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: script to send mqtt message with percentage

Post by salvacalatayud »

Try this flow:

Code: Select all

[{"id":"17010ea5.44ab11","type":"tab","label":"mqtt traductor salva","disabled":false,"info":""},{"id":"2f099dcf.665432","type":"comment","z":"17010ea5.44ab11","name":"Version: v.1.0.0","info":"","x":200,"y":140,"wires":[]},{"id":"e3fd556.de12ba8","type":"comment","z":"17010ea5.44ab11","name":"ABOUT","info":"This software originate from https://github.com/kungknut/Domoticz-MQTT-Translator\n\nIf you find a bug or want to contribute to make this software better? Feel \nfree to open an issue or a pull request.","x":170,"y":180,"wires":[]},{"id":"de6a25fe.da91c8","type":"mqtt out","z":"17010ea5.44ab11","name":"To 3rd party","topic":"","qos":"","retain":"","broker":"8bc033be.f9277","x":730,"y":480,"wires":[]},{"id":"4f21a53f.99596c","type":"mqtt in","z":"17010ea5.44ab11","name":"From 3rd party","topic":"#","qos":"0","broker":"8bc033be.f9277","x":200,"y":420,"wires":[["813bffcb.6c1a1"]]},{"id":"cc5613c.108d2f","type":"http request","z":"17010ea5.44ab11","name":"To Domoticz","method":"GET","ret":"txt","url":"","tls":"","x":730,"y":420,"wires":[[]]},{"id":"5e1ae03c.9df0b","type":"mqtt in","z":"17010ea5.44ab11","name":"From Domoticz","topic":"domoticz/out","qos":"0","broker":"8bc033be.f9277","x":200,"y":480,"wires":[["3a5786d1.d605ca"]]},{"id":"3a5786d1.d605ca","type":"function","z":"17010ea5.44ab11","name":"Format MQTT","func":"var domoticzServer = \"http://localhost\";\nvar userVarValues = flow.get(\"userVarValues\");\n\n// Find what row in the userVarValues array that hold the settings for the reporting device\nvar mqttPayload = JSON.parse(msg.payload);\nvar arrI = null;\nfor (var i = 0; i < userVarValues.length; i++){\n    if(mqttPayload.idx == userVarValues[i].devIdx){\n        arrI = i;\n    }\n}\n\n// If no match is found, exit this function and return null\nif(arrI !== null){\n    // Find out which type of device that submitted the value\n    var userVar = userVarValues[arrI];\n    if(typeof userVar.slope === 'undefined') userVar.slope = 1;\n    if(typeof userVar.intercept === 'undefined') userVar.intercept = 0;\n    if(userVar.type != \"switch\") var aval = (mqttPayload.svalue1 - userVar.intercept) / userVar.slope;\n    \n    switch(userVar.type) {\n        case \"dimmer\":\n            // DIMMER 0-100%\n            msg.topic = userVar.outTopic;\n            msg.payload = aval;\n            switch(mqttPayload.nvalue) {\n                case 0:\n                    msg.payload = 0;\n                    break;\n                case 1:\n                    msg.payload = context.get(userVar.outTopic)||50;\n                    break;\n                case 2:\n                    context.set(userVar.outTopic, aval);\n                    break;\n            }\n            break;\n        case \"switch\":\n            // SWITCH ON/OFF\n            // OBS - Domoticz is case sensitive\n            msg.topic = userVar.outTopic;\n            if(mqttPayload.nvalue == \"1\"){\n                msg.payload = \"ON\";\n            } else if (mqttPayload.nvalue == \"0\"){\n                msg.payload = \"OFF\";\n            }\n            break;\n        case \"shutter\":\n            // SHUTTER 0-100%\n            msg.topic = userVar.outTopic;\n            msg.payload = aval;\n            switch(mqttPayload.nvalue) {\n                case 0:\n                    msg.payload = 0;\n                    break;\n                case 1:\n                    msg.payload = 100;\n                    break;\n                case 2:\n                    context.set(userVar.outTopic, aval);\n                    break;\n                    }\n            break;\n        case \"svalue1\":\n            // Thermostat setpoint\n            msg.topic = userVar.outTopic;\n            msg.payload = aval;\n            break;\n        default:\n            msg.topic = null;\n    }\n}else {\n    msg.topic = null;\n}\n\nif(msg.topic !== null){\n    return msg;\n}","outputs":1,"noerr":0,"x":380,"y":480,"wires":[["cf7bf70d.710d38"]]},{"id":"813bffcb.6c1a1","type":"function","z":"17010ea5.44ab11","name":"Convert to url","func":"var domoticzServer = \"http://localhost:8080\";\nvar userVarValues = flow.get(\"userVarValues\");\n\n// Find what row in the userVarValues array that hold the settings for the reporting device\nvar arrI = null;\nfor (var i = 0; i < userVarValues.length; i++){\n    if(msg.topic == userVarValues[i].inTopic){\n        arrI = i;\n    }\n}\n\n// If no match is found, exit this function and return null\nif(arrI !== null){\n    // Find out which type of device that submitted the value\n    var userVar = userVarValues[arrI];\n    if(typeof userVar.limits === 'undefined') userVar.limits = \"0,0\";\n    if(typeof userVar.slope === 'undefined') userVar.slope = 1;\n    if(typeof userVar.intercept === 'undefined') userVar.intercept = 0;\n    if(userVar.type != \"switch\") var aval = (msg.payload * userVar.slope) + userVar.intercept;\n    \n    switch(userVar.type) {\n        case \"svalue\":  // Temperature, Percent, Pressure, Voltage, Text, Distance\n        case \"svalue1\": // Thermostat setpoint\n            msg.url = domoticzServer + \"/json.htm?type=command&param=udevice&idx=\" + userVar.devIdx + \"&nvalue=0&svalue=\" + aval;\n            break;\n        case \"shutter_old\": // Thermostat setpoint\n            msg.url = domoticzServer + \"/json.htm?type=command&param=udevice&idx=\" + userVar.devIdx + \"&nvalue=2&svalue=\" + aval;\n            break;\n        case \"humidity\":\n            // Humidity level\n            var humStat = 0; // 0 = Normal, 1 = Comfortable, 2 = Dry, 3 = Wet\n            var lims = userVar.limits.split(\";\");\n            var limits = [];\n            for (var i = 0; i < lims.length; i++){\n                var obj = lims[i].split(\",\");\n                if(aval >= obj[1]) humStat = obj[0];\n            }\n            msg.url = domoticzServer + \"/json.htm?type=command&param=udevice&idx=\" + userVar.devIdx + \"&nvalue=\" + aval + \"&svalue=\" + humStat;\n            break;\n        case \"switch\":\n            // Binary switch (ON/OFF)\n            // Domoticz is case sensitive\n            if(msg.payload == \"ON\" || msg.payload == \"OFF\"){\n                msg.payload = msg.payload.toLowerCase();\n                msg.payload = msg.payload.charAt(0).toUpperCase() + msg.payload.slice(1);\n                msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=\" + msg.payload;\n            }\n            break;\n        case \"dimmer\":\n            // Dimmer 0-100%\n            var level = parseInt(aval) + 1; // Bug in Domoticz require the \"in\" message to be 1 higher than actual value.\n            msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Set%20Level&level=\" + level;\n            if(msg.payload == \"0\"){\n                msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Off\";\n            }\n            break;\n        case \"shutter\":\n            // Shutter 0-100%\n            var level = parseInt(aval); // Bug in Domoticz require the \"in\" message to be 1 higher than actual value.\n            msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Set%20Level&level=\" + level;\n            if(msg.payload == \"0\"){\n                msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Off\";\n            }\n            break;\n        default:\n            msg.url = null;\n            break;\n    }\n} else {\n    msg.url = null;\n}\n\nif(msg.url !== null){\n    return msg;\n}","outputs":1,"noerr":0,"x":380,"y":420,"wires":[["f1960ba6.853bb8"]]},{"id":"65eafdbd.a7c764","type":"comment","z":"17010ea5.44ab11","name":"GET USER VARIABLES FROM DOMOTICZ","info":"","x":290,"y":240,"wires":[]},{"id":"e412dc01.a3452","type":"comment","z":"17010ea5.44ab11","name":"TRANSLATION FUNCTIONS","info":"","x":240,"y":380,"wires":[]},{"id":"5167d1a1.edf9e","type":"http request","z":"17010ea5.44ab11","name":"Read user variables","method":"GET","ret":"txt","url":"http://localhost:8080/json.htm?type=command&param=getuservariables","tls":"","x":380,"y":320,"wires":[["537a1ec2.9b5ba"]]},{"id":"537a1ec2.9b5ba","type":"function","z":"17010ea5.44ab11","name":"Cache to flow context","func":"msg.payload = JSON.parse(msg.payload);\nvar userVarRes = msg.payload.result,\n    userVarValues = [],\n    hueStats = {};\n\n\nfor (var i = 0; i < userVarRes.length; i++){\n    var obj = userVarRes[i];\n    for (var key in obj){\n        if(key == \"Value\"){\n            var val = JSON.parse(obj[key]);\n            if(val.MQTT !== undefined) {\n                userVarValues.push(val.MQTT);\n            }\n        }\n    }\n}\n\nflow.set(\"userVarValues\", userVarValues);\n\n//msg.payload = flow.get(\"userVarValues\");\n//return msg;","outputs":1,"noerr":0,"x":600,"y":320,"wires":[[]]},{"id":"9ae0eedd.09a41","type":"mqtt in","z":"17010ea5.44ab11","name":"trigger","topic":"nodered/update-uservar","qos":"2","broker":"8bc033be.f9277","x":170,"y":320,"wires":[["5167d1a1.edf9e"]]},{"id":"b84d9ce3.f5c28","type":"inject","z":"17010ea5.44ab11","name":"trigger","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":170,"y":280,"wires":[["5167d1a1.edf9e"]]},{"id":"f1960ba6.853bb8","type":"delay","z":"17010ea5.44ab11","name":"rateLim 2msg/s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":420,"wires":[["cc5613c.108d2f"]]},{"id":"cf7bf70d.710d38","type":"delay","z":"17010ea5.44ab11","name":"rateLim 1msg/s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":480,"wires":[["de6a25fe.da91c8"]]},{"id":"8bc033be.f9277","type":"mqtt-broker","z":"17010ea5.44ab11","broker":"localhost","port":"1883","clientid":"MQTTTRANSLATORNODEREDMQTTCLIENT","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]
Change your user variable type to "shutter"
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

salvacalatayud wrote: Friday 28 February 2020 18:07 Change your user variable type to "shutter"
hi, i imported your flow, but didn't working.

i also subscribe to topic:
tasmota_blind
but if i move slide inside domoticz i didn't see nothing.

this is my uservar:

Code: Select all

{"MQTT":{"devIdx" : 111,"inTopic" : "cmnd/tasmota_blind/shutterposition1","outTopic" : "stat/tasmota_blind/SHUTTER1","slope" : 1, "intercept" : 0,"limits" : "0,0","type" : "shutter"}
i also try to publish command like in the uservar:
topic = cmnd/tasmota_blind/shutterposition1
payload = 41
in this case the relay is triggered but can't see nothing:
1.jpg
1.jpg (78.65 KiB) Viewed 4642 times
i try to change the topic
topic = tasmota_blind
payload = shutterposition1 41
and now i'm able to see the subscriber but in this case the relay is not trigered
2.jpg
2.jpg (97.43 KiB) Viewed 4642 times

of course when i import your rednote i changed with my mqtt adress and domoticIP:port
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

salvacalatayud wrote: Friday 28 February 2020 18:07 Try this flow:

Code: Select all

[{"id":"17010ea5.44ab11","type":"tab","label":"mqtt traductor salva","disabled":false,"info":""},{"id":"2f099dcf.665432","type":"comment","z":"17010ea5.44ab11","name":"Version: v.1.0.0","info":"","x":200,"y":140,"wires":[]},{"id":"e3fd556.de12ba8","type":"comment","z":"17010ea5.44ab11","name":"ABOUT","info":"This software originate from https://github.com/kungknut/Domoticz-MQTT-Translator\n\nIf you find a bug or want to contribute to make this software better? Feel \nfree to open an issue or a pull request.","x":170,"y":180,"wires":[]},{"id":"de6a25fe.da91c8","type":"mqtt out","z":"17010ea5.44ab11","name":"To 3rd party","topic":"","qos":"","retain":"","broker":"8bc033be.f9277","x":730,"y":480,"wires":[]},{"id":"4f21a53f.99596c","type":"mqtt in","z":"17010ea5.44ab11","name":"From 3rd party","topic":"#","qos":"0","broker":"8bc033be.f9277","x":200,"y":420,"wires":[["813bffcb.6c1a1"]]},{"id":"cc5613c.108d2f","type":"http request","z":"17010ea5.44ab11","name":"To Domoticz","method":"GET","ret":"txt","url":"","tls":"","x":730,"y":420,"wires":[[]]},{"id":"5e1ae03c.9df0b","type":"mqtt in","z":"17010ea5.44ab11","name":"From Domoticz","topic":"domoticz/out","qos":"0","broker":"8bc033be.f9277","x":200,"y":480,"wires":[["3a5786d1.d605ca"]]},{"id":"3a5786d1.d605ca","type":"function","z":"17010ea5.44ab11","name":"Format MQTT","func":"var domoticzServer = \"http://localhost\";\nvar userVarValues = flow.get(\"userVarValues\");\n\n// Find what row in the userVarValues array that hold the settings for the reporting device\nvar mqttPayload = JSON.parse(msg.payload);\nvar arrI = null;\nfor (var i = 0; i < userVarValues.length; i++){\n    if(mqttPayload.idx == userVarValues[i].devIdx){\n        arrI = i;\n    }\n}\n\n// If no match is found, exit this function and return null\nif(arrI !== null){\n    // Find out which type of device that submitted the value\n    var userVar = userVarValues[arrI];\n    if(typeof userVar.slope === 'undefined') userVar.slope = 1;\n    if(typeof userVar.intercept === 'undefined') userVar.intercept = 0;\n    if(userVar.type != \"switch\") var aval = (mqttPayload.svalue1 - userVar.intercept) / userVar.slope;\n    \n    switch(userVar.type) {\n        case \"dimmer\":\n            // DIMMER 0-100%\n            msg.topic = userVar.outTopic;\n            msg.payload = aval;\n            switch(mqttPayload.nvalue) {\n                case 0:\n                    msg.payload = 0;\n                    break;\n                case 1:\n                    msg.payload = context.get(userVar.outTopic)||50;\n                    break;\n                case 2:\n                    context.set(userVar.outTopic, aval);\n                    break;\n            }\n            break;\n        case \"switch\":\n            // SWITCH ON/OFF\n            // OBS - Domoticz is case sensitive\n            msg.topic = userVar.outTopic;\n            if(mqttPayload.nvalue == \"1\"){\n                msg.payload = \"ON\";\n            } else if (mqttPayload.nvalue == \"0\"){\n                msg.payload = \"OFF\";\n            }\n            break;\n        case \"shutter\":\n            // SHUTTER 0-100%\n            msg.topic = userVar.outTopic;\n            msg.payload = aval;\n            switch(mqttPayload.nvalue) {\n                case 0:\n                    msg.payload = 0;\n                    break;\n                case 1:\n                    msg.payload = 100;\n                    break;\n                case 2:\n                    context.set(userVar.outTopic, aval);\n                    break;\n                    }\n            break;\n        case \"svalue1\":\n            // Thermostat setpoint\n            msg.topic = userVar.outTopic;\n            msg.payload = aval;\n            break;\n        default:\n            msg.topic = null;\n    }\n}else {\n    msg.topic = null;\n}\n\nif(msg.topic !== null){\n    return msg;\n}","outputs":1,"noerr":0,"x":380,"y":480,"wires":[["cf7bf70d.710d38"]]},{"id":"813bffcb.6c1a1","type":"function","z":"17010ea5.44ab11","name":"Convert to url","func":"var domoticzServer = \"http://localhost:8080\";\nvar userVarValues = flow.get(\"userVarValues\");\n\n// Find what row in the userVarValues array that hold the settings for the reporting device\nvar arrI = null;\nfor (var i = 0; i < userVarValues.length; i++){\n    if(msg.topic == userVarValues[i].inTopic){\n        arrI = i;\n    }\n}\n\n// If no match is found, exit this function and return null\nif(arrI !== null){\n    // Find out which type of device that submitted the value\n    var userVar = userVarValues[arrI];\n    if(typeof userVar.limits === 'undefined') userVar.limits = \"0,0\";\n    if(typeof userVar.slope === 'undefined') userVar.slope = 1;\n    if(typeof userVar.intercept === 'undefined') userVar.intercept = 0;\n    if(userVar.type != \"switch\") var aval = (msg.payload * userVar.slope) + userVar.intercept;\n    \n    switch(userVar.type) {\n        case \"svalue\":  // Temperature, Percent, Pressure, Voltage, Text, Distance\n        case \"svalue1\": // Thermostat setpoint\n            msg.url = domoticzServer + \"/json.htm?type=command&param=udevice&idx=\" + userVar.devIdx + \"&nvalue=0&svalue=\" + aval;\n            break;\n        case \"shutter_old\": // Thermostat setpoint\n            msg.url = domoticzServer + \"/json.htm?type=command&param=udevice&idx=\" + userVar.devIdx + \"&nvalue=2&svalue=\" + aval;\n            break;\n        case \"humidity\":\n            // Humidity level\n            var humStat = 0; // 0 = Normal, 1 = Comfortable, 2 = Dry, 3 = Wet\n            var lims = userVar.limits.split(\";\");\n            var limits = [];\n            for (var i = 0; i < lims.length; i++){\n                var obj = lims[i].split(\",\");\n                if(aval >= obj[1]) humStat = obj[0];\n            }\n            msg.url = domoticzServer + \"/json.htm?type=command&param=udevice&idx=\" + userVar.devIdx + \"&nvalue=\" + aval + \"&svalue=\" + humStat;\n            break;\n        case \"switch\":\n            // Binary switch (ON/OFF)\n            // Domoticz is case sensitive\n            if(msg.payload == \"ON\" || msg.payload == \"OFF\"){\n                msg.payload = msg.payload.toLowerCase();\n                msg.payload = msg.payload.charAt(0).toUpperCase() + msg.payload.slice(1);\n                msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=\" + msg.payload;\n            }\n            break;\n        case \"dimmer\":\n            // Dimmer 0-100%\n            var level = parseInt(aval) + 1; // Bug in Domoticz require the \"in\" message to be 1 higher than actual value.\n            msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Set%20Level&level=\" + level;\n            if(msg.payload == \"0\"){\n                msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Off\";\n            }\n            break;\n        case \"shutter\":\n            // Shutter 0-100%\n            var level = parseInt(aval); // Bug in Domoticz require the \"in\" message to be 1 higher than actual value.\n            msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Set%20Level&level=\" + level;\n            if(msg.payload == \"0\"){\n                msg.url = domoticzServer + \"/json.htm?type=command&param=switchlight&idx=\" + userVar.devIdx + \"&switchcmd=Off\";\n            }\n            break;\n        default:\n            msg.url = null;\n            break;\n    }\n} else {\n    msg.url = null;\n}\n\nif(msg.url !== null){\n    return msg;\n}","outputs":1,"noerr":0,"x":380,"y":420,"wires":[["f1960ba6.853bb8"]]},{"id":"65eafdbd.a7c764","type":"comment","z":"17010ea5.44ab11","name":"GET USER VARIABLES FROM DOMOTICZ","info":"","x":290,"y":240,"wires":[]},{"id":"e412dc01.a3452","type":"comment","z":"17010ea5.44ab11","name":"TRANSLATION FUNCTIONS","info":"","x":240,"y":380,"wires":[]},{"id":"5167d1a1.edf9e","type":"http request","z":"17010ea5.44ab11","name":"Read user variables","method":"GET","ret":"txt","url":"http://localhost:8080/json.htm?type=command&param=getuservariables","tls":"","x":380,"y":320,"wires":[["537a1ec2.9b5ba"]]},{"id":"537a1ec2.9b5ba","type":"function","z":"17010ea5.44ab11","name":"Cache to flow context","func":"msg.payload = JSON.parse(msg.payload);\nvar userVarRes = msg.payload.result,\n    userVarValues = [],\n    hueStats = {};\n\n\nfor (var i = 0; i < userVarRes.length; i++){\n    var obj = userVarRes[i];\n    for (var key in obj){\n        if(key == \"Value\"){\n            var val = JSON.parse(obj[key]);\n            if(val.MQTT !== undefined) {\n                userVarValues.push(val.MQTT);\n            }\n        }\n    }\n}\n\nflow.set(\"userVarValues\", userVarValues);\n\n//msg.payload = flow.get(\"userVarValues\");\n//return msg;","outputs":1,"noerr":0,"x":600,"y":320,"wires":[[]]},{"id":"9ae0eedd.09a41","type":"mqtt in","z":"17010ea5.44ab11","name":"trigger","topic":"nodered/update-uservar","qos":"2","broker":"8bc033be.f9277","x":170,"y":320,"wires":[["5167d1a1.edf9e"]]},{"id":"b84d9ce3.f5c28","type":"inject","z":"17010ea5.44ab11","name":"trigger","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":170,"y":280,"wires":[["5167d1a1.edf9e"]]},{"id":"f1960ba6.853bb8","type":"delay","z":"17010ea5.44ab11","name":"rateLim 2msg/s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":420,"wires":[["cc5613c.108d2f"]]},{"id":"cf7bf70d.710d38","type":"delay","z":"17010ea5.44ab11","name":"rateLim 1msg/s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":480,"wires":[["de6a25fe.da91c8"]]},{"id":"8bc033be.f9277","type":"mqtt-broker","z":"17010ea5.44ab11","broker":"localhost","port":"1883","clientid":"MQTTTRANSLATORNODEREDMQTTCLIENT","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]
Change your user variable type to "shutter"
just to be sure, this my information about mqtt:
MQTT Host 192.168.0.105
MQTT Port 1883
MQTT User DVES_USER
MQTT Client DVES_328390
MQTT Topic tasmota_blind
MQTT Group Topic cmnd/tasmotas/
MQTT Full Topic cmnd/tasmota_blind/
MQTT Fallback Topic cmnd/DVES_328390_fb
megamarco83
Posts: 109
Joined: Friday 21 September 2018 15:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script to send mqtt message with percentage

Post by megamarco83 »

additional information, i find inside raspberry in /var/log/daeomon.log

this:

Code: Select all

Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Format MQTT] TypeError: Cannot read property 'length' of undefined
Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Convert to url] TypeError: Cannot read property 'length' of undefined
Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Format MQTT] TypeError: Cannot read property 'length' of undefined
Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Convert to url] TypeError: Cannot read property 'length' of undefined
Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Format MQTT] TypeError: Cannot read property 'length' of undefined
Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Convert to url] TypeError: Cannot read property 'length' of undefined
Feb 29 17:43:26 raspberrypi Node-RED[265]: 29 Feb 17:43:26 - [error] [function:Format MQTT] TypeError: Cannot read property 'length' of undefined
it continue to increase, maybe is here the problem?

that's my "read user variable" inside node red:

Code: Select all

http://192.168.0.105:8085/json.htm?type=command&param=getuservariables
and this is the json if i put that string inside web brawser:

Code: Select all

{
   "result" : [
      {
         "LastUpdate" : "2019-12-19 08:45:12",
         "Name" : "Calorifero_Bagno_PT_manuale",
         "Type" : "0",
         "Value" : "0",
         "idx" : "3"
      },
      {
         "LastUpdate" : "2020-01-18 19:24:35",
         "Name" : "Calorifero_Bagno_Mansarda_manuale",
         "Type" : "0",
         "Value" : "0",
         "idx" : "4"
      },
      {
         "LastUpdate" : "2019-12-08 18:04:13",
         "Name" : "myRooms",
         "Type" : "2",
         "Value" : "{\"heater\":48,\"cooler\":49,\"selector\":\"Season\",\"rooms\":[{\"room\":\"room_A\",\"s\":42,\"t\":39,\"v\":45},{\"room\":\"room_B\",\"s\":43,\"t\":40,\"v\":46},{\"room\":\"room_C\",\"s\":44,\"t\":41,\"v\":47}]}",
         "idx" : "6"
      },
      {
         "LastUpdate" : "2020-02-26 21:36:35",
         "Name" : "blindControl",
         "Type" : "2",
         "Value" : "blind_esp32_1;Down;42",
         "idx" : "7"
      },
      {
         "LastUpdate" : "2019-09-13 00:23:37",
         "Name" : "dimmer",
         "Type" : "0",
         "Value" : "99",
         "idx" : "9"
      },
      {
         "LastUpdate" : "2018-12-30 22:06:57",
         "Name" : "led_dimmer",
         "Type" : "0",
         "Value" : "0",
         "idx" : "10"
      },
      {
         "LastUpdate" : "2019-09-13 00:28:59",
         "Name" : "dimm",
         "Type" : "0",
         "Value" : "90",
         "idx" : "11"
      },
      {
         "LastUpdate" : "2020-02-29 17:30:11",
         "Name" : "VCM_Mansarda_manuale",
         "Type" : "0",
         "Value" : "0",
         "idx" : "12"
      },
      {
         "LastUpdate" : "2020-02-04 11:45:11",
         "Name" : "VCM_Piano_Terra_manuale",
         "Type" : "0",
         "Value" : "0",
         "idx" : "13"
      },
      {
         "LastUpdate" : "2020-02-29 17:47:35",
         "Name" : "energyTrigger",
         "Type" : "2",
         "Value" : "This will trigger the dzVents script again",
         "idx" : "14"
      },
      {
         "LastUpdate" : "2020-02-29 17:47:35",
         "Name" : "hotWaterThermostatControlled",
         "Type" : "2",
         "Value" : "false",
         "idx" : "15"
      },
      {
         "LastUpdate" : "2020-02-29 17:37:29",
         "Name" : "hotWaterValvesESPBooted",
         "Type" : "2",
         "Value" : "ESP204_rebootMQTT",
         "idx" : "21"
      },
      {
         "LastUpdate" : "2020-02-29 17:47:35",
         "Name" : "PDC_manuale",
         "Type" : "0",
         "Value" : "0",
         "idx" : "22"
      },
      {
         "LastUpdate" : "2020-02-28 01:00:46",
         "Name" : "ValvolaTreVie_ESP205_REBOOT",
         "Type" : "2",
         "Value" : "Esp_TreVie_205_Rebooted",
         "idx" : "24"
      },
      {
         "LastUpdate" : "2020-02-27 20:21:51",
         "Name" : "IFTTTvar",
         "Type" : "2",
         "Value" : "[{\"obj\":\"piantana camera\",\"act\":\"On\"}]",
         "idx" : "25"
      },
      {
         "LastUpdate" : "2020-02-11 20:40:33",
         "Name" : "stoveControl",
         "Type" : "0",
         "Value" : "2",
         "idx" : "26"
      },
      {
         "LastUpdate" : "2020-02-29 17:18:45",
         "Name" : "reboot_sonoff",
         "Type" : "2",
         "Value" : "sonoff_200_rebootMQTT",
         "idx" : "27"
      },
      {
         "LastUpdate" : "2020-02-29 17:38:49",
         "Name" : "nodered",
         "Type" : "2",
         "Value" : "{\"MQTT\":{\"devIdx\" : 111,\"inTopic\" : \"stat/tasmota_blind/shutterposition\",\"outTopic\" : \"stat/tasmota_blind/shutterposition1\",\"slope\" : 1, \"intercept\" : 0,\"limits\" : \"0,0\",\"type\" : \"shutter\"}",
         "idx" : "28"
      }
   ],
   "status" : "OK",
   "title" : "GetUserVariables"
}

using the MQTTlens i see that if i use:
1) as topic to publish = cmnd/tasmota_blind/shutterposition
payload = 33 (for example to put blind at 33%)

2) i'm subscrive to:
cmnd/tasmota_blind/shutterposition1
i receive: 33

i'm subscrive to:
stat/tasmota_blind/RESULT
i receive:

Code: Select all

{"Shutter1":{"Position":33,"Direction":0},"Shutter2":{"Position":40,"Direction":0}}

{"POWER2":"OFF"}

{"Shutter1":{"Position":52,"Direction":-1},"Shutter2":{"Position":40,"Direction":0}}

{"ShutterPosition1":33}

{"POWER2":"ON"}
if i'm subscrive to topic:
domoticz/in

Code: Select all

{"idx":154,"nvalue":2,"svalue":"51","Battery":100,"RSSI":6
}


if i'm subscrive to topic:
domoticz/out

Code: Select all

{ "Battery" : 255, "LevelNames" : "Off|Level1|Level2|Level3", "RSSI" : 12, "SelectorStyle" : "0", "description" : "", "dtype" : "Light/Switch", "id" : "000140BF", "idx" : 111, "name" : "tapp_tasmota", "nvalue" : 2, "stype" : "Selector Switch", "svalue1" : "81", "switchType" : "Blinds Percentage Inverted", "unit" : 1 }
we should not interpretate this message to move or receive commands?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest