FHEM Forum

FHEM => English Corner => Thema gestartet von: jonjon am 28 August 2017, 20:45:51

Titel: mqtt and ReadingsVal
Beitrag von: jonjon am 28 August 2017, 20:45:51
hello, I have a problem from few week now with a notification base on mqtt action, and the ReadingsVal. I have esp32 connecting whit a RCWL-0516 and they are sending a mqtt message "client.publish("Beyren/ESP32/detect","1"); " or  "client.publish("Beyren/ESP32/detect","0");" when some one is moving.
But I couldn't understanding the ReadingsVal, if some one can help me to understand who this ReadingsVal is working with mqtt, it will be fantastic. :)
Fhem is reading the value 1 or 0 to Beyren/ESP32/detect but notify is completely wrong.

This is a part of my code :

define espAlarm MQTT_DEVICE
attr espAlarm IODev Mosquitto
attr espAlarm room Alarme
attr espAlarm stateFormat transmission-state
attr espAlarm subscribeReading_0 Beyren/ESP32/detect
attr espAlarm subscribeReading_1 Beyren/ESP32/detect
attr espAlarm subscribeReading_2 Beyren/ESP32/detect
define FileLog_espAlarm FileLog ./log/espAlarm-%Y.log espAlarm
attr FileLog_espAlarm logtype text
attr FileLog_espAlarm room Alarme

define test_esp32 notify espAlarm {\
if(Value("switch_Alarm") eq "on") {\
  if(ReadingsVal("espAlarm","state","2") eq "1") {\
  #if(ReadingsVal("2","state",0) eq "1") {\
   fhem("set Alarm_buzzer on")\
  }\
}\
}

thanks for the help :)
Titel: Antw:mqtt and ReadingsVal
Beitrag von: jonjon am 02 September 2017, 19:35:28
hello again, maybe my explanation was not so clear, I will try to do it shorter. I'm sending mqtt message for example on my root "Beyren/ESP32/detect/0" and I'm trying to make a event like start the light, star a alarm if the value is 1 (from 0 to 1), but I can't manage or understanding how is working, I have try the ReadingsVal, but I'm sure that the writing is wrong, if some one can give me some light of what to put on my ReadingsVal, it's will be a big help.
Thanks  :)
Titel: Antw:mqtt and ReadingsVal
Beitrag von: amenomade am 03 September 2017, 00:13:26
The result of  "list espAlarm" could help.
Titel: Antw:mqtt and ReadingsVal
Beitrag von: jonjon am 03 September 2017, 09:36:13
Hello amenomade thank, i tried and get this :

Internals:
   IODev      Mosquitto
   NAME       espAlarm
   NR         746
   STATE      incoming publish received
   TYPE       MQTT_DEVICE
   qos        0
   retain     0
   READINGS:
     2017-09-03 07:12:42   2               1
     2017-09-03 07:12:41   transmission-state incoming publish received
   message_ids:
   sets:
   subscribe:
     Beyren/ESP32/detect
   subscribeExpr:
     ^Beyren\/ESP32\/detect$
   subscribeReadings:
     Beyren/ESP32/detect 2
Attributes:
   IODev      Mosquitto
   room       Alarme
   stateFormat transmission-state
   subscribeReading_2 Beyren/ESP32/detect

--------------------
But still I can find the good write for the ReadingVal, I have try all this

if(ReadingsVal("espAlarm","state","2") eq "1") {\
if(ReadingsVal('espAlarm','2',"0") eq "1") {\
if(ReadingsVal("espAlarm","2","") eq "1") {\
if(ReadingsVal('detect$','2','1')) {\
if(ReadingsVal("detect$","2","0") eq "1") {\
if(ReadingsVal($detect, "2", 0) eq "1") {\
if(ReadingsVal("2","state",0) eq "1") {\

but nothing is working
Titel: Antw:mqtt and ReadingsVal
Beitrag von: amenomade am 03 September 2017, 12:00:48
if (ReadingsVal("espAlarm","2","") eq "1")should work. If not, the problem is somewhere else.

Try define test_esp32 notify espAlarm.*

You can also use only fhem commands:

define test_esp32 notify espAlarm.* IF ([switch_Alarm] eq "on" and [espAlarm:2] eq "1") (set Alarm_buzzer on)
Titel: Antw:mqtt and ReadingsVal
Beitrag von: jonjon am 04 September 2017, 13:46:44
Many thanks amenomade ! yes it's working "if (ReadingsVal("espAlarm","2","") eq "1")" I was close but one value was to mutch "if(ReadingsVal('espAlarm','2',"0") eq "1")". :)