MQTT for rules on INA219 gives an error

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

MQTT for rules on INA219 gives an error

#1 Post by costo » 07 Nov 2023, 01:25

Hi,

I'm using firmware version mega-20231013 and have a INA219 connected.
I want to use MQTT and sent data to domoticz and only use one task, so I use rules.

If I use MQTT, I get Error: MQTT: Invalid/Unhandled data received! (Topic: domoticz/in, Message: ("idx":20x)
for all 3 devices

Code: Select all

on INA219#V do
  Publish domoticz/in,{"idx":207,"nvalue":0,"svalue":"[INA219#V]"}
endon

on INA219#A do
  Publish domoticz/in,{"idx":208,"nvalue":0,"svalue":"[INA219#A]"}
endon

On INA219#W Do
  Publish domoticz/in,("idx":209,"nvalue":0,"svalue":"[INA219#W]")
endon
If I use the HTTP method it works, no error and devices get updated.

Code: Select all

on INA219#V do
  SendToHTTP 192.168.178.202,8080,/json.htm?type=command&param=udevice&idx=207&nvalue=0&svalue=[INA219#V]
endon

on INA219#A do
  SendToHTTP 192.168.178.202,8080,/json.htm?type=command&param=udevice&idx=208&nvalue=0&svalue=[INA219#A] 
endon

on INA219#W do
  SendToHTTP 192.168.178.202,8080,/json.htm?type=command&param=udevice&idx=209&nvalue=0&svalue=[INA219#W]
endon
What is wrong with the MQTT rule that I copied from the wiki tutorial on rules.

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: MQTT for rules on INA219 gives an error

#2 Post by Andrew Mamohin » 07 Nov 2023, 05:18

May be:

Code: Select all

Publish domoticz/in,'{"idx":207,"nvalue":0,"svalue":"[INA219#V]"}'
Andy.

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

Re: MQTT for rules on INA219 gives an error

#3 Post by TD-er » 07 Nov 2023, 08:59

Yep, you have comma's in your argument, which is a command argument separator.
So you must wrap the argument in quotes of a type which will not occur in your argument.
There are 3 types of quotes:

Code: Select all

`...`
'...'
"..."
So you can pick a quote to wrap the argument which is not being used in the argument itself, as suggested by Andrew

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: MQTT for rules on INA219 gives an error

#4 Post by costo » 07 Nov 2023, 15:34

Thank you Andrew, your suggestion with the quotes did the trick.

Thank you TD-er for explaining this in detail.

I suggest this is to be changed in the example in the wiki over here:

https://www.letscontrolit.com/wiki/inde ... th_own_IDX

there are no quotes around the MQTT example, that's why it ended up in this post ;)

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

Re: MQTT for rules on INA219 gives an error

#5 Post by Ath » 07 Nov 2023, 16:11

costo wrote: 07 Nov 2023, 15:34 I suggest this is to be changed in the example in the wiki over here:

https://www.letscontrolit.com/wiki/inde ... th_own_IDX

there are no quotes around the MQTT example, that's why it ended up in this post ;)
The Wiki is very outdated, more up to date documentation can be found in ReadTheDocs.
/Ton (PayPal.me)

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: MQTT for rules on INA219 gives an error

#6 Post by costo » 07 Nov 2023, 21:48

Ath wrote: 07 Nov 2023, 16:11 The Wiki is very outdated, more up to date documentation can be found in ReadTheDocs.
When looking at: https://espeasy.readthedocs.io/en/lates ... Rules.html
I see under the sub: Custom reports to Domoticz with own IDX

Code: Select all

MQTT

on INA219#Amps do
 Publish domoticz/in,{"idx":123456,"nvalue":0,"svalue":"%eventvalue1%"} //Own made up IDX 123456
endon

on INA219#Watts do
 Publish domoticz/in,{"idx":654321,"nvalue":0,"svalue":"%eventvalue1%"} //Own made up IDX 654321
endon
Also here no quotes around the argument.
For future reference , someone with editing rights, can change this ?

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

Re: MQTT for rules on INA219 gives an error

#7 Post by Ath » 07 Nov 2023, 23:03

I'll put that on my todo list, at some interval, a checkup on parts of the docs is needed indeed ;)
/Ton (PayPal.me)

bidrohini
Normal user
Posts: 105
Joined: 03 Nov 2022, 16:24

Re: MQTT for rules on INA219 gives an error

#8 Post by bidrohini » 09 Nov 2023, 14:59

costo wrote: 07 Nov 2023, 01:25

On INA219#W Do
Publish domoticz/in,("idx":209,"nvalue":0,"svalue":"[INA219#W]")
endon[/code]

Looks like there is a typo here. The 'on' should be in lower case.

Code: Select all

on INA219#W do
  Publish domoticz/in,{"idx":209,"nvalue":0,"svalue":"[INA219#W]"}
endon

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

Re: MQTT for rules on INA219 gives an error

#9 Post by Ath » 09 Nov 2023, 15:26

bidrohini wrote: 09 Nov 2023, 14:59 Looks like there is a typo here. The 'on' should be in lower case.
No, that doesn't matter, the script statements are handled case-insensitive. You should have found that in your searches for this answer...
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 36 guests