[SOLVED] MQTT and MQTT2_DEVICE

Begonnen von bmentink, 02 September 2019, 02:01:58

Vorheriges Thema - Nächstes Thema

Beta-User

Sorry for that.

Would you mind issuing
set mqtt2_server publish /Garden/Aeroponics/Pump 1
and have a look, what happens in the EventMonitor? There should be a response of the ESP...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

Beta-User

After some tests with mosquitto_sub, pls try the following:

attr ESP8266 setList on:noArg /Garden/Aeroponics/Pump 1\
off:noArg /Garden/Aeroponics/Pump 0\
Manual_Auto:uzsuToggle,1,0 /Garden/Aeroponics/Manual_Auto $EVTPART1\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 setStateList on off
attr ESP8266 stateFormat Solution_Conductivity: Conductivity\
state

There had been a " ", one to much "\" aso. due to some copying...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bmentink

#32
No good still. The buttons still don't do the right things. Publishing manually with:
set mqtt2_server publish /Garden/Aeroponics/Pump 1 works fine and I get the right MQTT traffic, and the ESP8266 does the right thing.

Also doing:
set mqtt2_server publish /Garden/Aeroponics/Manual_Auto 1 etc does the correct thing also ... it is not the publishing that is the issue, it is the way you have configured the buttons.

When I hit the Pump on/off button I get MQTT message "set_on" and "set_off" not "1" or "0" as expected ..

When I hit the Manual_Auto button I get the MQTT message "set 1" or "set 0" sent ... not "1" or "0" as expected ..

This is the 3rd time I have explained that, I have also asked, why is the "set" being sent, what gives with that, what do you not understand?

This is why I went over to the English Forum, as I think we are having Language issues ....

Beta-User

The "set..." is added by the MQTT2_DEVICE module, but this only happens to the reading values, but has _nothing_ to do what is sent out as paylaod via MQTT protocol.

Did you test the latest version i published here?

Note: Different to what I thought, the rawEvents do _not_ show what is published, but solemny what is received by the MQTT2_SERVER. To see the complete MQTT traffic, you have to use extrenal tools like mosquitto_sub or MQTTT.fx.
Using that and your latest RAW code, I noticed payoad of "1 " (on) and "1\" beeing sent. IMO this is what should be changed, not more. But It's not easy to see, as e.g. blanks just seem to be "nothing", and "\" in this notation usually just means "new line", so sorry for me not having put more focus on that earlier...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

rudolfkoenig

I just fixed an issue with MQTT2_SERVER, where the server wasnt sending the data when the client was subscribing just #, and the topic started with /.
Not sure if it helps in this case, though.

Btw. if you want to see the "raw" data sent as an event (e.g. in the Event Monitor), then you need to set the rePublish attribute of the MQTT2_SERVER to one, beside setting rawEvents to .*

Beta-User

Thanks for having a look, Rudi and also the additional info about how to make MQTT2_SERVER give more feedback about MQTT traffic.

Don't think the "/-start" of the topic has been the real problem, as direct sending through the IO has worked. You may correct me, if I'm wrong, but it shouldn't make any difference if it's MQTT2_DEVICE handing over the same thing to the server to send or if you use the direct command.

As already mentionned, there has been some small pieces of info. That "small noise" may bave made part of the payload causing irritations in the  client software on the ESP side.
Not sure, but perhaps we sould eliminate blanks "around" the payload to avoid similar problems in the future? (On the other hand: at least I am more focused on that kind of things now - first time this happens here...)
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bmentink

#36
Zitat von: Beta-User am 08 September 2019, 08:05:36
The "set..." is added by the MQTT2_DEVICE module, but this only happens to the reading values, but has _nothing_ to do what is sent out as paylaod via MQTT protocol.

When I press the "Pump" button, it is mean't to Publish/write the topic, not read. So why am I seeing the set_off/on message on publish? does not make sense ..
(I repeat, I am only seeing the "set_on" "set_off" message when I press the Pump button!)

Zitat
Did you test the latest version i published here?

Yes, this is what I have so far?:


define ESP8266 MQTT2_DEVICE dc_4f_22_18_e3_f5_72
attr ESP8266 IODev mqtt2_server
attr ESP8266 readingList /Garden/Aeroponics/SolarIntensity:.* SolarIntensity\
/Garden/Aeroponics/SolarAccumulation:.* SolarAccumulation\
/Garden/Aeroponics/Conductivity:.* Conductivity\
/Garden/Aeroponics/Pump_Status:.* { $EVENT ? {"state"=>"on"} : {"state"=>"off"} }\
/Garden/Aeroponics/Manual_Auto:.* Manual_Auto\
/Garden/Aeroponics/Threshold:.* Threshold
attr ESP8266 room Aeroponics
attr ESP8266 setList on:noArg /Garden/Aeroponics/Pump 1 \
off:noArg /Garden/Aeroponics/Pump 0 \
Manual_Auto:uzsuToggle,1,0 /Garden/Aeroponics/Manual_Auto $EVTPART1 \
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 setStateList on off
attr ESP8266 stateFormat Solution_Conductivity: Conductivity \
state
attr ESP8266 webCmd on:off:Manual_Auto:Threshold

setstate ESP8266 Solution_Conductivity: 1218 \
off
setstate ESP8266 2019-09-09 07:39:25 Conductivity 1218
setstate ESP8266 2019-09-08 16:01:59 Manual_Auto 1
setstate ESP8266 2019-09-06 07:58:38 Pump_Status 0
setstate ESP8266 2019-09-09 07:39:24 SolarAccumulation 3122
setstate ESP8266 2019-09-09 07:39:25 SolarIntensity 20
setstate ESP8266 2019-09-08 16:01:59 Threshold 26
setstate ESP8266 2019-09-09 07:36:41 state off


Here is the eventMonitor window with rePublish=1

2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 Conductivity: 1220
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1220
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 SolarIntensity: 42
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/SolarIntensity:42
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 SolarAccumulation: 2971
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/SolarAccumulation:2971
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 Manual_Auto: 0
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Manual_Auto:0
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 Manual_Auto: set 0
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 Manual_Auto: 0
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Manual_Auto:0
2019-09-09 09:57:04 MQTT2_DEVICE ESP8266 Conductivity: 1222
2019-09-09 09:57:04 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1222
2019-09-09 09:57:05 MQTT2_DEVICE MQTT2_mqtt2_server Pump: 0
2019-09-09 09:57:05 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Pump:0
2019-09-09 09:57:05 MQTT2_DEVICE ESP8266 set_off
2019-09-09 09:57:05 MQTT2_DEVICE ESP8266 Conductivity: 1221
2019-09-09 09:57:05 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1221
2019-09-09 09:57:06 MQTT2_DEVICE ESP8266 Conductivity: 1220
2019-09-09 09:57:06 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1220
"""
2019-09-09 09:57:28 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1220
2019-09-09 09:57:29 MQTT2_DEVICE ESP8266 Conductivity: 1222
2019-09-09 09:57:29 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1222
2019-09-09 09:57:30 MQTT2_DEVICE ESP8266 Conductivity: 1224
2019-09-09 09:57:30 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1224
2019-09-09 09:57:30 MQTT2_DEVICE MQTT2_mqtt2_server Pump: 1
2019-09-09 09:57:30 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Pump:1
2019-09-09 09:57:30 MQTT2_DEVICE ESP8266 set_on
2019-09-09 09:57:31 MQTT2_DEVICE ESP8266 Conductivity: 1219
2019-09-09 09:57:31 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1219
2019-09-09 09:57:32 MQTT2_DEVICE ESP8266 Conductivity: 1221


Is the "Pump:1" the problem? Should it not be "Pump 1"?


EDIT: I did an update, now I am seeing this when I turn pump on, I am still not seeing "Pump_status" change to "1" (which it should do if my ESP8266 detected the correct MQTT message )

2019-09-09 11:44:17 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1224
2019-09-09 11:44:17 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Pump:1
2019-09-09 11:44:17 MQTT2_DEVICE ESP8266 set_on
2019-09-09 11:44:17 Global global ATTR MQTT2_mqtt2_server readingList mqtt2_server:/Garden/Aeroponics/Pump:.* Pump
2019-09-09 11:44:17 MQTT2_DEVICE MQTT2_mqtt2_server Pump: 1
2019-09-09 11:44:18 MQTT2_DEVICE ESP8266 Conductivity: 1224
2019-09-09 11:44:18 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1224




bmentink

#37
My old fhem.cfg before you did all these changes works as intended, it results in:


define ESP8266 MQTT2_DEVICE dc_4f_22_18_e3_f5_72
attr ESP8266 IODev mqtt2_server
attr ESP8266 eventMap 1:ON 0:OFF
attr ESP8266 readingList dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarIntensity:.* SolarIntensity\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarAccumulation:.* SolarAccumulation\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Conductivity:.* Conductivity\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Pump_Status:.* Pump_Status\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Manual_Auto:.* Manual_Auto\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Threshold:.* Threshold
attr ESP8266 room Aeroponics
attr ESP8266 setList Pump:uzsuSelectRadio,1,0 /Garden/Aeroponics/Pump $EVTPART1\
Manual_Auto:uzsuSelectRadio,1,0 /Garden/Aeroponics/Manual_Auto $EVTPART1\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 stateFormat Solution_Conductivity: Conductivity\
Pump Status: Pump_Status
attr ESP8266 webCmd Pump:Manual_Auto:Threshold

setstate ESP8266 Solution_Conductivity: 1231\
Pump Status: OFF
setstate ESP8266 2019-09-09 12:52:51 Conductivity 1231
setstate ESP8266 2019-09-09 12:52:28 Manual_Auto 1
setstate ESP8266 2019-09-09 12:52:25 Pump_Status 0
setstate ESP8266 2019-09-09 12:52:51 SolarAccumulation 2674
setstate ESP8266 2019-09-09 12:52:51 SolarIntensity 76
setstate ESP8266 2019-09-09 12:50:50 Threshold 26
setstate ESP8266 2019-09-09 12:52:28 state Manual_Auto


Both the pump and Pump_Status work correctly as well as Manual_Auto.

I think there is issues with uzsuToggle, it seems to have three states, not two. uzsuSelectRadio as above works correctly.

Beta-User

Zitat von: bmentink am 08 September 2019, 21:40:49
When I press the "Pump" button, it is mean't to Publish/write the topic, not read. So why am I seeing the set_off/on message on publish? does not make sense ..
(I repeat, I am only seeing the "set_on" "set_off" message when I press the Pump button!)
One more attempt to explain this: FHEM handles several layers of information and differenciates between some internal classifications. Wrt. to the "layers" you might compare it to MS Excel: There's the "text" (that in many cases is a formula), the "result", some general formating (for number values, e.g.) and some cell formating (text and background color aso.).

My personal approach is to try to get as much as reasonalbe into the "formula". This should help to get the entire thing automatically "formatted" by internal mechanisms FHEM offers and also make it usable as close to the standard of any FHEM device as possible.

"set_on" and so on are internal values, but _not_ the message, your device will get. So the long story of this
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Manual_Auto:0
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 Manual_Auto: set 0
2019-09-09 09:56:55 MQTT2_DEVICE ESP8266 Manual_Auto: 0
2019-09-09 09:56:55 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Manual_Auto:0
is:
- You clicked the Manual_Auto-0 button in your browser showing FHEMWEB (or issued the corresponding command "set ESP8266 Manual_Auto 0").
- This will lead to the following three intermediate results (two of them represented by the first two lines):
-- The payload "0" will be puplished to "/Garden/Aeroponics/Manual_Auto"
-- An "event" is generated (could be used e.g. to derive further actions within FHEM towards other devices): The "Reading" named "Manual_Auto" ond device "ESP 8266" has been set to "set 0" (I assume, setStateList has still been defined when doing this part of the test? Otherwise the event should have been different...)
-- The device will show a new reading content in FHEMWEB (not long visible though, as the answer from the device is cooming very fast ;) )

Lines 3+4 are dealing with incoming information:
- line 3 shows the dispatching of the answer of the ESP8266 microcontroller. There the payload shown in line 4 as "0" is filled in the reading named "Manual_Auto" and overwrites the "old" content (as explained, this was "set 0").
- line 4 is just the incoming answer shown also as event (the lines are ordered that way as "throwing events" is generally more like a final action within FHEM when new info arrives). So this is just showing the topic "/Garden/Aeroponics/Manual_Auto" beeing updated from "somewhere" with payload "0".

(As already explained, if a second client would listen to the server from outside, it would not be able to distinguish between what's have been a command (from FHEM) or a state message (originating from your microcontroller); imo this should be changed in the next version of your firmware...)

So after doing an update (to get Rudi's changes), I'd propose to do some small changes to the latest "working" version you posted. Intention is to get to a final version in several steps that I expect to be easier to understand. So the first iteration should be:

demod ESP8266 MQTT2_DEVICE dc_4f_22_18_e3_f5_72
attr ESP8266 IODev mqtt2_server
attr ESP8266 eventMap 1:on 0:off
attr ESP8266 readingList dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarIntensity:.* SolarIntensity\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarAccumulation:.* SolarAccumulation\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Conductivity:.* Conductivity\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Pump_Status:.* Pump_Status\
/Garden/Aeroponics/Pump_Status:.* { $EVENT ? {"state"=>"on"} : {"state"=>"off"} }\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Manual_Auto:.* Manual_Auto\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Threshold:.* Threshold
attr ESP8266 room Aeroponics
attr ESP8266 setList Pump:uzsuSelectRadio,1,0 /Garden/Aeroponics/Pump $EVTPART1\
on:noArg /Garden/Aeroponics/Pump 1\
off:noArg /Garden/Aeroponics/Pump 0\
Manual_Auto:uzsuSelectRadio,1,0 /Garden/Aeroponics/Manual_Auto $EVTPART1\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 stateFormat Solution_Conductivity: Conductivity\
Pump Status: Pump_Status\
state
attr ESP8266 webCmd Pump:Manual_Auto:Threshold

To explain the changes:
Changing the "eventMap" and "stateFormat" should just be some kind of simple "skinning" (a little like applying a currency formatting in Excel => if the calculated value is a number, it's shown als a money value...). FHEM preferes lowercase states, and you should then see some icons (bulbs) instead of text.

Then there's some additional setters and incoming message handling. This should help you to get a better understanding of what I tried to explain in the MQTT traffic + event analysis above.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bmentink

#39
Many thanks for the elaborate reply  :)

I am now understanding a bit more the internals ..

I did an "update" again, and made the changes you specified for the first iteration. They work as intended.

Initially I have the words  "Solution_Conductivity: 1213 Pump Status: OFF Manual_Auto" , also the pump and manual_auto radio buttons
visible.
When I set the manual_auto to "0", and actuate the pump, I see the standard light bulb appear & lit, and when I set pump to off, it goes out as expected.
When I set manual_auto to "1" then the bulb is replaced by the words Manual_Auto again. When the pump comes on automatically, the words Manual_AUto get replaced by the bulb icon again, and it stays that way. Is that what you expect?

I think the main problem why it was not working in the past, was the line:
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Pump_Status:.* Pump_Status
/Garden/Aeroponics/Pump_Status:.* { $EVENT ? {"state"=>"on"} : {"state"=>"off"} }


I thought that the 2nd line "replaced" the first line, not "added to it" .. that probably was the reason my manual_auto switch would not work correctly .... my bad  :(

Looking forward to the 2nd iteration ...

Beta-User

#40
 :)

OK, sounds to go to the right direction, but there are still some questions on my side:
- What is complete unclear to me is the way "Auto_Manual" and "Pump" are influencing each other on the ESP side. There seem to be some kind of interdependency. Can you explain a little more on that? (Again: My understanding until now was "Pump" beeing some kind of main switch turning the entire system on and off. Only the way it works is reflected by the Auto/Manual setting. Is this wrong?)
- When clicking on the bulb representing "state", you should have the "Pump_Status" and "state" toggling. Does this work as expected?

What you could do now, is to

- add a setStateList:
attr ESP8266 setStateList on offThis will change where the clicks will be shown and what reading content is written: Without, every set command will be written to "state", by adding that, only on and off commands will change state, all other commands will be written to other readings (as "set <value>").

- only in case, "Pump" is meant to be some kind of mains switch: Then "Pump"/"Pump_Status" should _only_ be reflected in the "state" reading. So indeed, the second line is meant to replace the first ;) .  If the "information circle" with the "state" icon works as expected, you may delete everything else, that's related to the reading "Pump_Status" and the setList entry for "Pump" and also delete the reading itself to avoid future confusion on that.

Hope, this clear enough to try it yourself?
You may review my earlier posts here also ;) .
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bmentink

Zitat von: Beta-User am 10 September 2019, 08:38:38

- What is complete unclear to me is the way "Auto_Manual" and "Pump" are influencing each other on the ESP side. There seem to be some kind of interdependency. Can you explain a little more on that? (Again: My understanding until now was "Pump" beeing some kind of main switch turning the entire system on and off.

Hi,

No, Pump is not a "main switch". I will try and explain again.

1. Pump is just that, a pump I want to turn off and on, just a part of the system. Pump_Status is just feedback from the ESP that the pump has indeed turned on. (to be indicated by the bulb)
2. Manual_Auto is just a switch that allows Manual operation of the pump, or automatic operation of the pump due to a custom algorithm
The Manual_Auto switch has to be in manual mode (0) to allow manual operation of the "Pump" switch. In Auto mode(1), the pump switch is ignored. Hope this is as clear as mud. ;)

Cheers,


Beta-User

#42
Ok,

then we could consider about indicating the basic operation mode as "state" (e.g. to be shown as "manual" or "auto")?!?

So I'd propose to to one step in between:
defmod ESP8266 MQTT2_DEVICE dc_4f_22_18_e3_f5_72
attr ESP8266 IODev mqtt2_server
attr ESP8266 readingList /Garden/Aeroponics/SolarIntensity:.* SolarIntensity\
/Garden/Aeroponics/SolarAccumulation:.* SolarAccumulation\
/Garden/Aeroponics/Conductivity:.* Conductivity\
/Garden/Aeroponics/Pump_Status:.* { $EVENT ? {"Pump"=>"on"} : {"Pump"=>"off"} }\
/Garden/Aeroponics/Manual_Auto:.* { $EVENT ? {"mode"=>"auto"} : {"mode"=>"manual"} }\
/Garden/Aeroponics/Threshold:.* Threshold
attr ESP8266 room Aeroponics
attr ESP8266 setList Pump:on,off {my $modeval = $EVTPART1 eq "on" ? 1 : 0;;"/Garden/Aeroponics/Pump $modeval"}\
mode:auto,manual {my $modeval = $EVTPART1 eq "auto" ? 1 : 0;;"/Garden/Aeroponics/Manual_Auto $modeval"}\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 setStateList on off
attr ESP8266 stateFormat Mode: mode\
Solution_Conductivity: Conductivity\
Pump Status: Pump
attr ESP8266 webCmd Pump:mode:Threshold

(Will not look too nice, but first, we should get the two "information circles" for manual/auto mode and Pump closed...)

If that works (and auto/manual is agreed to be kind of very important basic info, you may try to use the "state" reading instead of "mode". (Note: there are some old reading names no longer used here, you may use "deletereading ESP8266 .*" to only see new readings from now on).

The new thing in the above is the use of some pieces of Perl code to get the translation from (readable) FHEM command to MQTT topic/payload done (see "mode" and "Pump" in the setList).

EDIT: Should be $EVTPART1 instead of "$EVTPART0"..?
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bmentink

#43
Hi,

I tried that ... still not quite right.

I get a light bulb for "Pump" and it responds to Pump_status message from the ESP, however it also responds to the pump switch regardless of the auto/manual switch.
As I said  .."The light should ONLY respond to Pump_Status!, not the state of the pump switch.

Cheers

EDIT: Actually it does operate correctly, the changes just took awhile to settle down .. :)
I also removed stateFormat Mode: mode, as that adds no value for me .. but apart from the looks it all works well, thanks.


I have downloaded FTUI, so will have a look at that ...

bmentink

So the final working version looks like this:
define ESP8266 MQTT2_DEVICE dc_4f_22_18_e3_f5_72
attr ESP8266 IODev mqtt2_server
attr ESP8266 readingList dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarIntensity:.* SolarIntensity\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarAccumulation:.* SolarAccumulation\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Conductivity:.* Conductivity\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Pump_Status:.* { $EVENT ? {"Pump"=>"on"} : {"Pump"=>"off"} }\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Manual_Auto:.* { $EVENT ? {"mode"=>"auto"} : {"mode"=>"manual"} }\
dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Threshold:.* Threshold
attr ESP8266 room Aeroponics
attr ESP8266 setList Pump:on,off {my $modeval = $EVTPART1 eq "on" ? 1 : 0;;;;"/Garden/Aeroponics/Pump $modeval"}\
mode:auto,manual {my $modeval = $EVTPART1 eq "auto" ? 1 : 0;;;;"/Garden/Aeroponics/Manual_Auto $modeval"}\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 stateFormat Solution_Conductivity: Conductivity\
Pump Status: Pump\
\

attr ESP8266 webCmd Pump:mode:Threshold

setstate ESP8266 Solution_Conductivity: 1268\
off Status: off\
\

setstate ESP8266 2019-09-11 15:38:03 Conductivity 1268
setstate ESP8266 2019-09-11 15:37:04 Pump off
setstate ESP8266 2019-09-11 15:38:03 SolarAccumulation 27182
setstate ESP8266 2019-09-11 15:38:03 SolarIntensity 220
setstate ESP8266 2019-09-11 15:33:17 Threshold 28
setstate ESP8266 2019-09-11 15:37:07 mode auto
setstate ESP8266 2019-09-11 15:37:07 state mode