FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: bmentink am 02 September 2019, 02:01:58

Titel: [SOLVED] MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 02 September 2019, 02:01:58
Hi All,

I am very new to Fhem and have a question about setting up MQTT.

I have a mosquito server and have defined the MQTT device ok,  as the event window says it is connected, so far so good.
I then would like a client to listen to the server, I presume this is the MQTT2_DEVICE, if so I am having trouble linking it to my mqtt device.

With MQTT my device name is "mqtt" and with MQTT2_DEVICE the device name is "mqtt_dev", it is very confusing on how all the mqtt things are linked together ..

I also try to use MQTT2_CLIENT but I get this error: Unknown module MQTT2_CLIENT

I am running on a freeNAS server .. and have installed all the perl modules I could find for MQTT

Please help
Cheers
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 02 September 2019, 09:28:33
Welcome to our community.

First of all: did you update FHEM to the most recent version (note: updates in FHEM are initiated inside FHEM, not via OS mechanisms like apt-get)? MQTT2_CLIENT beeing missed indicates a rather old version (as all MQTT2-Modules had been under heavy development the last 12 Months).

Then you may not combine a TYPE=MQTT interface module with MQTT2_DEVICE, this is only for use with MQTT_DEVICE, MQTT_BRIDGE or MQTT_GENERIC_BRIDGE type of client definitions.

So first update (and restart) FHEM, then either use MQTTDEVICE as client device or define a MQTT2_CLIENT to support MQTT2_DEVICE type of clients (which imo is easier to configure than MQTT_DEVICE).

If you are rather new to the MQTT world and do not need MQTT data in a larger setup, you might also consider using MQTT2_SERVER instead of mosquitto+MQTT or mosquitto+MQTT2_CLIENT. This in most cases is the easiest way to handle MQTT protocol in FHEM.
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 02 September 2019, 21:50:01
Many thanks for your reply & welcome.

I have downloaded the latest version of fhem, but I am running on a FreeNAS server (based on FreeBSD) which may not be as so up to date as Linux. So I guess I am stuck with standard MQTT for now. (It runs Perl5)

Yes, I have created my device with MQTT and have an instance of MQTT_DEVICE that I am trying to get working.
Can you offer an example of a "slider" control that uses the MQTT_DEVICE to publish a topic? I am struggling with the documentation ..

EDIT: Oops, I forgot the update, I now have the MQTT2 classes .. thanks. Could you give the above example based on MQTT2. Thanks.
I have managed to get all the Readings automatically from the MQTT2_DEVICE, but I am struggling to get a user gui that connects to the Readings. For example, How do I create a user Switch that sends publish on/off events .. I did the dummy switch, but that is as far as I got ..


Regards,
Bernie
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 03 September 2019, 05:19:13
Hi again,

I notice that if I have autocreate turned on, my MQTT2_DEVICE gets loaded with Readings which is good and a log file auto associated.

So I turn off autocreate, rename the MQTT2 device that has a name that includes the CID to something readable. That works and log file gets renamed.

However if I turn off the power to the mqqt device that is publishing events, and turn back on again. THat device that got created does not update it's Readings.

I have to turn on autocreate again, and it creates a NEW device with a different CID that does update Readings.

How do I get a consistent device if the CID keeps changing on power cycle .. that just won't work for me.

PS: I am feeling a bit like a second class citizen, as there is no manual (Heimautomatisierung-mit-FHEM.pdf ) in English for me to read, so all I have is the on-line help.
Also, all youtube videos are only in German .
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 03 September 2019, 09:46:43
OK, the CID issue is rather hard to explain - even in German... (So I try to avoid that at least for now).

First: Do you really need en external MQTT server like mosquitto? The issue you described just doesn't exist when using MQTT2_SERVER instead.

Then: When using MQTT2_CLIENT as IO, I'd recommend to configure a "special" MQTT2_DEVICE instance to try to sort out corresponding information. This uses the structure of the topic tree. As a starting point, FHEM provides a so called attrTemplate named "A_00_MQTT2_CLIENT_general_bridge" which is able to deal with "typical" topic trees of some popular devices like shelly and tasmota.

For more templates (including several to easily configure tasmota-based switches), just use "set <yourMQTT2-device> attrTemplate ?" to get more info (in English... :) .).

To get help to configure your device(s) (if still needed after a short look at the attrTemplate feature), it would be helpful to provide more info, "list" or "RAW Definition" (I prefer the later in MQTT2 context) is needed (use code tags/ # button to make them easier to read). Based on that it would also be easier to explain the CID thing ;) (if still necessary).



Wrt. your critics on the docu:
- The most important and up to date part is the commandref (what you see using help within FHEM). For official modules, it's mandatory for module authors to provide at least an english version. So this is the best authorized info _everyone_ gets. It may be very short, but in most cases, the most important keywords are explained to an extend allowing to get things up and running. There are a few exeptions, though... So just avoid modules not providing sufficient info - (imo explicitly the very popular DOIF module provides a really poor English version).

- Despite there's no 1:1 translation of the pdf (btw: the German version is also not up-to-date...), the wiki contains at least english versions of the most important basic instructions, see especially https://wiki.fhem.de/wiki/Quick-Start/en and https://wiki.fhem.de/wiki/First_steps_in_FHEM. You'll find also some more links to english versions of other important stuff there.

- Wrt. to "the youtube videos": There's especially one individual providing a serie of videos on FHEM. These videos - for good reason - are not part of the official docu; my personal view on the ones I had a look on: despite them containing often good ideas, they very often suffer from logical or technical mistakes and misleading information; additionally, they are not beeing updated. So just use them as kind of inspiration and better think twice before copy/paste these "instructions".

In case you have suggestions on how to enhance the English part of the official documentation on FHEM feel free to contribute...
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: rob am 03 September 2019, 10:38:01
Hello bmentink.

Your goal seems to be getting a human readable friendlyname for your device. Am I right? Beta-User already gave you a deeper support. I wasn´t that fast  :D

What about setting an alias alternatively?

You could just put attr yourdevicename alias yourfriendlyname into the global command field on top of the page and hit enter.

I´m not sure if it helps in every case, but it may be worth giving it a try :)

Kind regards
rob

PS: Please don't feel this way. Imho 99% of all manuals, descriptions and stuff in the internet are not in German. Nobody translates it for me  :'(
Beta-User gave you support in English. If I would ask vice versa a question in German in a English board, I surely won´t get any help  ;D  How should I feel then?
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 03 September 2019, 10:41:25
Hi,

Thanks for the replies ..

Regarding the CID issue, that was the fault of the MQTT device, it was changing the CID every boot to stay unique, I have reprogrammed that to not do that, and all is well ..

The MQTT device I am trying to talk to is a custom ESP8266 module that is set up as an Aeroponics controller.

Regarding the MQTT client, I am using MQTT2_SERVER and MQTT2_DEVICE ..

I just need some help with setting up attributes to MQTT2_DEVICE to enable me to connect switches and set/read topics.
I have a list of readings on MQTT2_DEVICE so the server etc is working, and I can log some data ..
It is not clear to me how to publish/subscribe to the server using MQTT2_DEVICE, or should I be using a BRIDGE?
(I asked about how to set up a slider control earlier, still in the dark how to relate it to MQTT2_DEVICE)

Just an example of a switch publishing on/off, and a slider publishing number 1..100, my device is called MQTT2_AERO

I have attached photo of where I have got so far ..

Thanks again.

PS: Guys, I am not having ago about the documentation, just frustrated at not being able to put my hands on the right stuff to get started.I Apologize if my reply was harsh, it was not meant to be   :)
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 03 September 2019, 11:05:06
Zitat von: bmentink am 03 September 2019, 10:41:25
It is not clear to me how to publish/subscribe to the server using MQTT2_DEVICE, or should I be using a BRIDGE?
It should be possible to configure all that stuff within the one MQTT2_DEVICE for the Aeroponics controller. To send out any MQTT data/commands, a setList is needed. You may find a lot of ideas in the file behind the attrTemplate stuff: https://svn.fhem.de/trac/browser/trunk/fhem/FHEM/lib/AttrTemplate/mqtt2.template. To give more or detailed support, I'd need more info on your setup and especially the exact topic-payload-combinations to send out (just what mosquito_pub would issue; to make tests, you can use the publish command at your MQTT2_SERVER device).

For configuring other, less special devices (tasmota-based, e.g.), I'd recommend using the attrTemplate feature - then you may have a look at the completely configured devices allowing easier transfer to the Aeroponics thing?

Zitat
PS: Guys, I am not having ago about the documentation, just frustrated at not being able to put my hands on the right stuff to get started.I Apologize if my reply was harsh, it was not meant to be   :)
Nevermind. Imo you just sounded frustrated, not harsh. For the future: just provide clear feedback in case you have constructive suggestions, this might be helpfull to others in the same situation :D . (Btw.: I myself had also been very frustrated about the partly outdated german and english info provided in the past - the only way out is to continuously try to improve these and keep up with the speed of developent... - For this reason there also exists a german wiki page trying to get a more or less complete introduction in MQTT2_DEVICE: https://wiki.fhem.de/wiki/MQTT2-Module_-_Praxisbeispiele. Perhaps you could use a automated translator to get at least some benefit from it.)

Please note: you are by far not the only guy lost in the variety of options, the MQTT protocol offers (or the client devices may require).
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 03 September 2019, 22:56:28
Hi,

Please understand I am NOT using the mosquitto, I am using MQTT2_SERVER!

The two links you give are just as confusing for me ... too complicated.

I have had a look at the setList & getList attributes of MQTT2_DEVICE and they don't make sense either, they both talk about publishing topics, when you want to react to a topic from a sensor, why do you need to publish? (I am talking about sensors that send topics at a regular rate .. so I just need to display the info)

I appreciate the help but you have not answered my questions.

1. How do I set up a simple ON:OFF switch that publishes a topic, when the switch changes state  (i.e how do I connect a switch to a topic, I.E. dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Pump)
2. An example of a "slider" control sending a topic to the mqtt server when it changes value. (I.E. I want to send changes to dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Threshold)
3. I want to see in my Aeroponics ROOM the value of dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/SolarIntensity,  it has the readingList item SolarIntensity)

I have attached a picture of my mqqt device and it's current readings ..

I don't know how I can be clearer .. :(
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 04 September 2019, 08:30:52
Try the following, please:
attr MQTT2_AERO setList Pump_Status:ON,OFF /Garden/Aeroponics/Pump $EVTPART1\
Threshold:slider,0,0.5,10 /Garden/Aeroponics/Threshold $EVTPART1
attr MQTT2_AERO webCmd Pump_Status:Threshold
attr MQTT2_AERO stateFormat SolarIntensity

(Code snipplet is ment to be entered in a multiline command field; to get one, just klick on the "+" icon left to the command field or use the RAW-Option, see pictures included here: https://wiki.fhem.de/wiki/Import_von_Code_Snippets (https://wiki.fhem.de/wiki/Import_von_Code_Snippets)).
If this leads in the right direction, I'd suggest to add a link in the other post in the english corner and close it to avoid double postings. So other non-German speaking users may be forwarded to this thread?

Wrt. to the other points you mentioned:
- mosquitto_pub (and mosquitto_pub) are commandline tools that may be used with any MQTT server. So if one is used to these tools, it's no problem using them to communicate to a MQTT2_SERVER instance as well.
- To get single informations displayed in the room there are at least 4 options: the above "stateFormat SolarIntensity" beeing one of them (you may add more readings and text also).

For the future, please do not use pictures but RAW definitions instead (see above) - so anyone could easily transfer the device e.g. to a test system ;) .
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 04 September 2019, 09:13:18
Hi,

Thanks. Would be good if explained how the lines of code work for my education.

What I see is not very GUI friendly though (have a look at attached image) the slide has no border so di not see it initially, it is the box with 22. It does work though setting the threshold.

The pump control is the empty box, if I press on it I see a drop-down list ON/OFF if I select ON, the pump does not turn on ...
(I will check that it expects ON/OFF, it may be 0/1 )

The other number 5 is the Intensity, so that works  ..

How do I nice them up, there needs to be labels, borders, I thought these would be there ..

I am sorry, I am used to OpenHAB which does everything for you. BUt I do like the way Fhen is totally configurable ..

NOTE: I have renamed the device to ESP8266 .. just to be confusing :)
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: rob am 04 September 2019, 09:22:30
Hi.

Could you please throw
list ESP8266
into the command box on top and paste the result here?

Kind regards
rob
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 04 September 2019, 09:25:01
Sure, sorry still a picture as I havn't worked out RAW yet ..
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 04 September 2019, 09:57:27
Please add a final post in the other thread referrring to the discussion to be continued here and close it (this is an exeptional procedure, due to the double posting), so others may find the following remarks also:

The setList (and very similar also getList) works as follows:
Pump_Status:ON,OFF /Garden/Aeroponics/Pump $EVTPART1
- Pump_Status refers to the reading name to be set. As you already got the status (for local switching, I guess) of the pump sent by the Aeroponics-hardware (seems to be a ESP8266 based self-made thing?), I've chose (at first instance, more to be explained later...) this as a starting point.
- the ":" seperates the reading name from a value selection (or a widget in case of the threshold, see below).
- The rest is a topic / payload pair, $EVTPART1 there represents the selected value returned by the widget we use in part 1. (Note: if needed, you may use a perl function returning topic and payload here (in {}, as usual).

Every line represents one reading (exception: state, see the code from supernova1963 in the other thread; I'll come back to that later).

Wrt. to the "look" of the whole thing: It's completely customizable, you may use all the widgets you find here: https://wiki.fhem.de/wiki/FHEMWEB/Widgets (https://wiki.fhem.de/wiki/FHEMWEB/Widgets), they also work in an MQTT2_DEVICE context.
So eg. this might be alternatives (note: for testing purpose with 0/1 as pump payload): attr MQTT2_AERO setList Pump_Status:uzsuToggle,1,0 /Garden/Aeroponics/Pump $EVTPART1\
Threshold:colorpicker,BRI,0,0.5,10 /Garden/Aeroponics/Threshold $EVTPART1


Zitat von: Beta-User am 04 September 2019, 08:41:20
I'll make some annotations to the differences wrt. the on/off thing later in the other thread, as this may be valueable for others also.
[...]
So is there any description on the MQTT interface of your Aeroponics system? Especially: you provided (some) info about the topic structure, but not really about the payload (seemed to be ON and OFF wrt. to the pump) nor the range of the threshold.
So my guess with ON/OFF seems to be wrong. Please provide info about what to send (or at least a link to eg. a github repo with the code on the ESP8266), if above 0/1 doesn't work.

Wrt. to labeling: The look in FHEMWEB can be influenced in several ways, also using additional modules (represent one or more reading values in additional FHEM-devices) is possible. E.g. for commands within the device the webCmdLabel attribute is available (see wiki link above or https://wiki.fhem.de/wiki/DeviceOverview_anpassen (https://wiki.fhem.de/wiki/DeviceOverview_anpassen)). to some extent stateFormat can also help. As there may be some more changes to come, I'd suggest to have a look at this in a later phase. For now, please just make a short test with
attr MQTT2_AERO stateFormat Solar: SolarIntensityPlease: just copy text, do not add pictures.

see also "list -r ESP8266" or "list -r MQTT2_AERO"(in case both are there, decide, which one to use for the future and delete the other one. Otherwise, we will risk non consistent results from the autocreate feature).
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 04 September 2019, 22:36:16
Hi @Beta-User,

Wow, thanks, that really helps a lot, I can now start to link pieces together ..

I have the pump switch working, I did not make it clear to you that "Pump" was the topic to send, "Pump_Status" is what is returned from the ESP8266 as feedback that the pump really did turn on. I modified the code example you sent to reflect that, and it worked.
(ON/OFF was correct)

Regarding the GUI. I will read up on the Widgets, I tried the colorpicker instead of slider and that is better but number hard to read, but it will do for now .. what I would really like is a GUI that looks like "example1" given on your home page, that would be awesome, but I have no idea how to get from here to there at the moment ..
(The label on Solar Intensity works ..)
I could not get uzsuToggle to work correctly. It looks ok in the device window, but when I go to my Room it shows up weird with an initial label of "Intensity", then when you click on it, it says "Pump" .... in the device setup it correctly has ON/OFF when you toggle ..
Not sure what goes on there ..

But I am now making good progress, thanks again for the help ..

PS: I tried closing the other thread, but it would not let me ..
PPS: I only have ESP8266 device, I had renamed MQTT2_AERO to ESP8266, there is not two devices ..

Cheers



Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 04 September 2019, 22:52:47
Thanks for your positive feedback, glad to hear you making good progress :) .

Please note:
- As Pump seems to be kind of general on/off, you should try to get this (in both directions) into a "special" reading called "state". This e.g. gives the option to work with so called SetExtensions including especially "on-for-timer" commands.
(To get that to work properly, we will need on/off as lower case setters (seperate for both, that part is easy) and feedback interpretation (that's a little more advanced)).
(Btw.: Perhaps with your growing background knowledge it's now a good idea to have a look in the mentioned attrTemplate-file ;) ).

- Wrt. to the look and feel, you'd better provide exact links ;)

If you provide more info on the whole thing (and some RAW codes from FHEM as text), it would be easier to explain the necessary changes.

- Thx for the last post in the other thread, please additionally use the "close" button (locatet somewhere below the first post).
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 05 September 2019, 00:24:03
Hmmm,
For some reason my buttons are not sending ON/OFF events anymore, here is the device text.

Zitatdefine 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:.* 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:ON,OFF /Garden/Aeroponics/Pump $EVTPART1\
Manual_Auto:ON,OFF /Garden/Aeroponics/Manual_Auto $EVTPART1\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 stateFormat Solar Intensity: SolarIntensity
attr ESP8266 webCmd Pump:Manual_Auto:Threshold

setstate ESP8266 Solar Intensity: 14
setstate ESP8266 2019-09-05 10:23:37 Conductivity 1297
setstate ESP8266 2019-09-05 09:18:26 Manual_Auto 0
setstate ESP8266 2019-09-05 08:46:10 Pump_Status 0
setstate ESP8266 2019-09-05 09:18:26 SolarAccumulation 293
setstate ESP8266 2019-09-05 09:18:25 SolarIntensity 14
setstate ESP8266 2019-09-05 10:19:43 Threshold 27
setstate ESP8266 2019-09-05 10:19:43 state Threshold

From event window: Note Pump has no value sent ...
Zitat2019-09-05 10:40:53 MQTT2_DEVICE ESP8266 Pump
2019-09-05 10:40:54 MQTT2_DEVICE ESP8266 Conductivity: 1299
2019-09-05 10:40:54 MQTT2_DEVICE ESP8266 SolarIntensity: 50
2019-09-05 10:40:54 MQTT2_DEVICE ESP8266 SolarAccumulation: 400

EDIT: My bad, my device expects 1:0 not ON:OFF as I indicated earlier ... all working again.
Even though the topic sends 0:1, is there a way for the Button to display ON:OFF and display the name of the button?
(I am using uzsuSelectRadio  buttons now)

EDIT2: I did do a "eventMap 1:ON 0:OFF" so my events get displayed as ON/OFF, but it did not help with the button values.

Thanks
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 05 September 2019, 00:38:30
Zitat von: Beta-User am 04 September 2019, 22:52:47
- Thx for the last post in the other thread, please additionally use the "close" button (locatet somewhere below the first post).

I only see a "Remove" button, and like I said, It won't let me ..

ZitatWrt. to the look and feel, you'd better provide exact links ;)
https://fhem.de/TabletUI_1.png
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 05 September 2019, 09:49:38
OK, thanks for the RAW code (no need to change "defmod", see "help defmod", code tags instead of quote is better (# icon)).

I'd suggest the following changes, but unfortunately couldn't fully test it, especially the handling of the Pump_Status topic is just a first guess...
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/Threshold:.* Threshold
attr ESP8266 setList on:noArg /Garden/Aeroponics/Pump 1\
off:noArg /Garden/Aeroponics/Pump 0\
Manual_Auto:uzsuToggle,ON,OFF /Garden/Aeroponics/Manual_Auto $EVTPART1\
Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 setStateList on off
attr ESP8266 stateFormat state\
Solar Intensity: SolarIntensity
attr ESP8266 webCmd Manual_Auto:Threshold

To see if it really works you should do two tests:
- try to switch the thing from outside FHEM (local switch or web interface) => state should change, and
- unpower it, switch from within FHEM => you should see the state remaining set_on or set_off which leads to a lamp with a exclamation mark to be dispayed in the device overview.

Wrt. to the deletion of "dc_4f_22_18_e3_f5_72:/Garden/Aeroponics/Manual_Auto:.* Manual_Auto\" from the readingList: Under any circumstance avoid using the same topic for sending commands/info _to_ the target hardware and receive feedback _from_ it. This may lead to infinite loops....


In case state feedback does not work properly, I'd need the MQTT traffic going back and forth. To get that, use the "rawEvents" attribute of the MQTT2_SERVER, in our case ".*" will be ok.
Then open a second browser window and do some switch procedures from within FHEM, then some locals in the ESP's web interface (assuming, it has one...).
Btw.: This is a good instrument for debugging MQTT issues ;) .



Wrt. to the "closing": There should be two additional buttons (in my case: on the left below the ones you cited, but I may have different settings for forum use). Afaik, you are allowed to close all the threads you opened.


Wrt. to the UI thing:

The linked picture shows a different UI called FTUI. This needs further customisation, so I'd recommend to have a look at that as soon as you are familiar with the basic functionality of the internal data and "timer" and "event" handling FHEM offers.

My personal focus is more on "automation", not too much on shiny UI design, so I'm only familiar with FHEMWEB, especially it's "f18" style. There's a second, rather new and not yet officially distributed Java-based style for FHEMWEB called "flex" you may have a look at. It may offer a more shiny UI without the need to "learn the FTUI language" in parallel to FHEM mechanisms.

If you want absolutely to start with UI customisation, you may search the forum for the keyword "FUIP". This is a tool for easy creation of FTUI (-alike(?)) pages, the tool's author (!) also provides some video material on that. (Please search the forum for it, imo this should not be part of this thread).
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 05 September 2019, 12:10:20
Great,  :) I will have a look at that tomorrow ... it is my bed time ..

Quick question: We seem to have lost the "Pump" button in your above code, I don't see it in webCmd.
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 05 September 2019, 12:16:49
It's not "lost" - your pump schould be switchable via the "state" icon which now is part of the stateFormat ;) . So no additional graphical element is needed any longer.

Wrt. to the look (and perhaps functionality) we might get back to that later, in addition a devStateIcon attribute might be usefull. As soon as state works bidirectional, you may have a second look on "Device Overview anpassen".

See you "tomorrow"  :) .
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 05 September 2019, 22:35:09
@Beta-User
Hi, I have tried your changes, but have seemed to go backwards now to a broke system again ..

I end up with a Toggle button, but it has the words "set 0" or "set 1" on it, and when you press it the MQTT topic
sent is "set 0/1" I also end up with a light bulb that does nothing (and I have no idea what change added it :( )

You do realize that the Topic "Pump"  with payload 0/1 is what is sent to turn the pump on/off and "Pump_Status"
with payload 0/1 is what is replied from the device in confirmation?

I presume your changes where intended to light the bulb when I get a "1" in Pump_status?

What you may not be aware off, is that the Manual_Auto topic (payload 1/0) needs to be in Manual mode (0)
to operate the "Pump" switch .. I had to change that line to:

Manual_Auto:uzsuToggle,1,0 /Garden/Aeroponics/Manual_Auto $EVTPART1

Look forward to further changes ..
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 05 September 2019, 22:53:41
OK, so this attempt was too eager, the devStateIcon seems not to automatically work.

As a first step, please just add on/off commands to the webCmd and change the auto/manual thing; now should be as follows:

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/Threshold:.* Threshold
attr ESP8266 setList on:noArg /Garden/Aeroponics/Pump 1\
  off:noArg /Garden/Aeroponics/Pump 0\
  Manual_Auto:uzsuToggle,0,1 /Garden/Aeroponics/Manual_Auto $EVTPART1\
  Threshold:colorpicker,BRI,0,1,100 /Garden/Aeroponics/Threshold $EVTPART1
attr ESP8266 setStateList on off
attr ESP8266 stateFormat state\
Solar Intensity: SolarIntensity
attr ESP8266 webCmd on:off:Manual_Auto:Threshold


The most important point will be to get the ESP's feedback on on/off commands in "state" reading as text on/off. If the switching itself works with the seperate icons from webCmd, I'll need the info what's going on on the MQTT traffic side as already described.

(Now, it's up to me to go to bed...)
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 05 September 2019, 23:22:05
You have a good night.

When you wake, please look at the attached image (sorry, I know you don't like pictures, but it is the only way to describe what is going on)

I can click on the on/off words and the light bulb changes state with the "!", that is because I can not change the state of Manual_Auto, it still has the "set 0/1" thing going on .. if I keep pressing SET  in the device window, it keeps adding "set" so I can get "set set set 0" sent ..

On the MQTT message front, the message that gets sent when pressing the Pump "on" button is "set_on" and for the "off" button "set_off"
So my device is not going to respond to those, as it is expecting 1 or 0 ..
The "state" variable has "set_on/off" as well ..

Very odd ..

The way I see this working, is:

1. The light bulb should "ONLY" respond to Pump_Status topics of "1" or "0", it should NOT be tied to a switch.
2. The "Pump" switch should indicate on/off to the GUI, but send topics "1" or "0"
3. For "Manual_Auto" switch, it should as 2. above, but should indicate a status from the subscribed topic of the same name,
(I know that is not ideal, but my device takes care of any "loops")

Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 06 September 2019, 09:31:59
Zitat von: bmentink am 05 September 2019, 23:22:05
When you wake, please look at the attached image (sorry, I know you don't like pictures, but it is the only way to describe what is going on)
Good Evening/Morning, I took a look :) .

But still, I'd get a better "picture" of what's really going on, if you'd added two things:
- The output of RAW definition as text (in code-tags) => This allows me (and others) to get the (besides some skinning identical) picture you attached in my own test system and includes some additional info that may have been usefull ;)
- The log of the MQTT traffic you are referring to (the "set_on" is the reading value as long as there is no feedback from the ESP, but the payload sent out via MQTT should be different). If you want to use other than "rawEvent .*" output of MQTT2_SERVER in the Event-Monitor, use tools like mosquito_sub or MQTT.fx to listen to the MQTT2_SERVER from outside FHEM.

So please provide both of the above.

Zitat
The way I see this working, is:

1. The light bulb should "ONLY" respond to Pump_Status topics of "1" or "0", it should NOT be tied to a switch.
2. The "Pump" switch should indicate on/off to the GUI, but send topics "1" or "0"
Imo, point 2 _should_ already work pretty close to that as a result of e.g.
attr ESP8266 setList on:noArg /Garden/Aeroponics/Pump 1\This should lead to payload "1" when setting the device on (but one can _only_ see this to work properly in the MQTT traffic, _not_ (really) in the FHEM-device-Overview or readings). As this seem to be kind of main switch, I'd recommend to use the "state" reading for this info - this is what you probably find to be somehow irritating.
If it's not kind of main switch, we'll have to get back to a different notation, but for the moment, I'd ask for some patience on that issue. You may decide _after_ it's working the "main switch way" if you insist in  expectation as described in your point 1. ;) .

(If you even want to get more irritated, delete the setStateList attribute and do some switching of different elements like also Threshold ;) ).

Zitat3. For "Manual_Auto" switch, it should as 2. above, but should indicate a status from the subscribed topic of the same name,
(I know that is not ideal, but my device takes care of any "loops")

Imo, there are more arguments to keep in mind. First one:
You finally want to have a shiny UI. There are some more options than only FTUI/FUIP. One is to use MQTT based other HA software like OpenHAB ;) . So one can combine the total flexibility within FHEM with a shiny UI... But: How to get OpenHAB to distinguish between FHEM commands and info coming from the device itself? They are on the same topic, but different to within FHEM, the origin (CID) most likely is no longer visible.

Second:
I'm not sure, but also MQTT2_SERVER _might_ filter out "double" info to avoid loops. So this might be the cause we don't get proper feedback on switching "Manual_Auto".

So I'd really recommend to use different topics for commands and feedback, shouldn't be very hard to implement in the firmware. (You may add the code and ask for help, there's quite a lot of guys hanging around here with "some" experience on firmware coding... Just make sure to delete "critical" info like WiFi passwords).
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 06 September 2019, 11:08:10
HI there, here is the RAW output of the device:

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: 1285\
off\

setstate ESP8266 2019-09-06 21:06:33 Conductivity 1285
setstate ESP8266 2019-09-06 16:13:08 Manual_Auto 1
setstate ESP8266 2019-09-06 07:58:38 Pump_Status 0
setstate ESP8266 2019-09-06 21:06:34 SolarAccumulation 1005
setstate ESP8266 2019-09-06 21:06:34 SolarIntensity 5
setstate ESP8266 2019-09-06 16:13:08 Threshold 26
setstate ESP8266 2019-09-06 21:03:22 state off


Please let me know if I have done anything wrong ..

Cheers
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 06 September 2019, 12:00:55
OK, (I indeed have been a little frustrated about having to repeat some earlier writings, but for now, everything's ok, beside the fact, the MQTT traffic still is missing ;D )

For the moment, the most important info seems to be this:
setstate ESP8266 2019-09-06 21:03:22 state off

So I'm quite sure, there is feedback on the pump-on command and this feedback is handled correctly as on/off in state.

Now the bulb icon should be shown without the red exclamation mark (might take some short time to change) and act as kind of toggle button. Can you please confirm on both? (And on the fact, the red ! will stay, when the ESP is not reachable, eg. by unpowering it).

If yes: why not only use this as grafical element to switch the pump and reduce webCmd to "Manual_Auto:Threshold"?
To avoid future confusion on that delete the Pump_Status reading, as this will not be updated any longer:
deletereading ESP8266 Pump_Status
For the Auto/Manual thing:
We could try to "translate" 1/0 to better readable format, but this would require some more work better to be done as soon as set topic and feedback topic are different. Then we could use some Perl, pretty similar to what is done with "Pump_Status". Are you working on the topic issue?
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 06 September 2019, 22:32:10
I am sorry you have been frustrated, so am I. You must remember you are a long time developer, I have just been on this code a few days ..

The line: setstate ESP8266 2019-09-06 21:03:22 state off  rarely happens ....

Most of the time it looks like this:
setstate ESP8266 2019-09-07 08:23:32 state set_on

I havn't given you MQQT traffic yet because I am not sure where to get it from, if you mean the event monitor,
here is a sample:

When I activate the pump(on,off):
2019-09-07 08:29:16 MQTT2_DEVICE ESP8266 Conductivity: 1251
2019-09-07 08:29:16 MQTT2_DEVICE ESP8266 set_on
2019-09-07 08:29:17 MQTT2_DEVICE ESP8266 Conductivity: 1250
2019-09-07 08:29:18 MQTT2_DEVICE ESP8266 Conductivity: 1250
2019-09-07 08:29:18 MQTT2_DEVICE ESP8266 set_off
2019-09-07 08:29:19 MQTT2_DEVICE ESP8266 Conductivity: 1251
2019-09-07 08:29:20 MQTT2_DEVICE ESP8266 Conductivity: 1251
2019-09-07 08:29:21 MQTT2_DEVICE ESP8266 Conductivity: 1252


When I hit The Manual_Auto sw (Twice):
2019-09-07 08:31:07 MQTT2_DEVICE ESP8266 Conductivity: 1250
2019-09-07 08:31:07 MQTT2_DEVICE ESP8266 Manual_Auto: set 0
2019-09-07 08:31:08 MQTT2_DEVICE ESP8266 Conductivity: 1250
2019-09-07 08:31:09 MQTT2_DEVICE ESP8266 Manual_Auto: set set 0
2019-09-07 08:31:09 MQTT2_DEVICE ESP8266 Conductivity: 1251
2019-09-07 08:31:10 MQTT2_DEVICE ESP8266 Conductivity: 1251
2019-09-07 08:31:11 MQTT2_DEVICE ESP8266 Conductivity: 1251


Now you see what I am getting? The messages are all wrong!
Also, The bulb always has a question mark.
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 07 September 2019, 07:53:36
Hmm, to see also the MQTT traffic in the EventMonitor, you have to set an attribute on the IO (TYPE=MQTT2_SERVER).
In your case:
attr mqtt2_server rawEvents .*

If you get "sometimes" the right result, I'd assume there's a communication problem on the WiFi side. Please have a look at this and make sure, we have a reliable connection. Otherwise we would have to use extended MQTT functionality (QoS ?); that would also be new to me.

Wrt to knowledge level: "developer" is somehow ridiculous, and mostly due to my activities in the attrTemplate file for MQTT2_DEVICE. So I know quite some things wrt to "skinning" and (functional) "design" of MQTT2_DEVICE for FHEMWEB, but there the story ends very quickly ::) ... Additionally, I'm not too familiar in explaining things in English ;D .
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 07 September 2019, 09:13:04
No, it is nothing to do with the WiFi, my original code works fine, both pump & Manual_Mode do the right thing, and I get all the MQTT traffic messages.

With your modifications, I don't.
See:
2019-09-07 19:04:24 MQTT2_DEVICE ESP8266 Conductivity: 1327
2019-09-07 19:04:24 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1327
2019-09-07 19:04:24 MQTT2_DEVICE ESP8266 set_off
2019-09-07 19:04:25 MQTT2_DEVICE ESP8266 Conductivity: 1326
2019-09-07 19:04:25 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1326
2019-09-07 19:04:26 MQTT2_DEVICE ESP8266 Conductivity: 1327
2019-09-07 19:04:26 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1327
2019-09-07 19:04:27 MQTT2_DEVICE ESP8266 set_on
2019-09-07 19:04:27 MQTT2_DEVICE ESP8266 Conductivity: 1327
2019-09-07 19:04:27 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1327
2019-09-07 19:04:28 MQTT2_DEVICE ESP8266 Conductivity: 1327
2019-09-07 19:04:28 MQTT2_SERVER mqtt2_server /Garden/Aeroponics/Conductivity:1327
2019-09-07 19:04:29 MQTT2_DEVICE ESP8266 Conductivity: 1327
2019-09-07 19:04:29 MQTT2_SERVER mqtt2_server /Garden/


Now here I set the pump off and on, I see the messages "set_off and "set_on, as above, but there are no MQTT traffic as a result, so something is wrong, the messages are not being sent. Anyway, "1" and "0" should be sent, as I said many times.

You have not explained why I am seeing the messages "set_off" etc, where does the "set" come from? That got introduced with your changes.

I think I will go pack to my code that worked (I saved the .cfg file) and then look further at the UI improvment/frontends etc as you mentioned.

At least with my original code I have a "working system". :) But many thanks for the learning experience.

Cheers,
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 07 September 2019, 09:30:14
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...
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 07 September 2019, 09:46:18
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...
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 08 September 2019, 04:09:58
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 ....
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag 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.

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...
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: rudolfkoenig am 08 September 2019, 12:22:17
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 .*
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 08 September 2019, 12:57:00
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...)
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 08 September 2019, 21:40:49
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



Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 09 September 2019, 02:54:45
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.
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 09 September 2019, 10:18:47
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.
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 09 September 2019, 22:20:16
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 ...
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 10 September 2019, 08:38:38
 :)

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 ;) .
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 10 September 2019, 10:25:55
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,

Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 10 September 2019, 12:00:04
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"..?
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 10 September 2019, 23:55:00
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 ...
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 11 September 2019, 05:39:47
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


Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 11 September 2019, 07:34:27
Great to hear, things now work to your satisfaction :) .

I'd recommend to have two additional things to be changed, but if it's really the "final working version" in your eyes, I'm fine with that also ;) . Imo, the final thing should look nice in FHEMWEB, have three grafical elements to control it (also with grafical representation of the mode and pump status...) and having some additional text about solar and moisture data ::) .
Feel free to ask in case you need additional info about that (remember: this thread might serve as a showcase for others desiring docu in English language...)

Wrt to FTUI, as already mentionned, FUIP may help to get quick start.

Enjoy :) .
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: bmentink am 11 September 2019, 07:37:03
And many thanks for helping me ... much appreciated  8)
Titel: Antw:MQTT and MQTT2_DEVICE
Beitrag von: Beta-User am 11 September 2019, 09:23:55
You're welcome!

Would you mind marking this thread as [solved]? (Just edit the first post and change the title there).