Autor Thema: mqtt publish with extra timestamp  (Gelesen 624 mal)

Offline kroonen

  • Full Member
  • ***
  • Beiträge: 137
mqtt publish with extra timestamp
« am: 09 Juli 2018, 18:42:47 »
I have an smoke device, and I want to publish the state and time with mqtt

I have this
fhem> l Rookzolder
   IODev      mqtt
   NAME       Rookzolder
   NR         102
   STATE      Clear
     2018-07-09 17:54:49   battery         100.00
     2018-07-09 17:54:49   rook            {"battery":"100.00","voltage":3185,"smoke":false}
     2018-07-09 17:54:49   smoke           0
     2018-07-09 17:54:49   transmission-state incoming publish received
     2018-07-09 17:54:49   voltage         3185
     zigbee2mqtt/smokezolder 0
       name       rook
   IODev      mqtt
   eventMap   0:Clear 1:Fire
   room       Zolder
   stateFormat smoke
   subscribeReading_rook zigbee2mqtt/smokezolder

and a publish

fhem> l rookzolder_mqtt
   DEF        Rookzolder
   IODev      mqtt
   NAME       rookzolder_mqtt
   NOTIFYDEV  Rookzolder
   NR         106
   NTFY_ORDER 50-rookzolder_mqtt
   STATE      outgoing publish sent
     2018-07-09 17:54:49   transmission-state outgoing publish sent
     smoke      /zigbee2mqtt/smoke1
   IODev      mqtt
   publishReading_smoke /zigbee2mqtt/smoke1
   stateFormat transmission-state

I now get a publish at /zigbee2mqtt/smoke1 the value : Clear

What I want is the value: Clear at 17:54:49

So with the timestamp.

Is this possible, and how?

regards Richard

Offline Beta-User

  • Developer
  • Hero Member
  • ****
  • Beiträge: 5938
  • Eigentlich USER! svn: templates mqtt2+httpmod
Antw:mqtt publish with extra timestamp
« Antwort #1 am: 11 Juli 2018, 10:45:15 »
Imo it's not clear what you want to achieve.

Do you want to change the STATE of the device from "Clear" to "Clear at 17:54:49" or do you really want to publish the combined info towards somewhere else?

If It's the first approach, you may use a different Perl-function in stateFormat transforming the '"smoke":false"' to the desired format. As a general remark: If you are looking for an option to have a "one look" how recent your values are, better use other ways like readingsGroup or readingsProxy. If you want to check a device for regular updates, use a watchdog.
In general imo it's better to keep both elements separated (clear and timestamp).

If you want to publish the combined info to a different place/topic, use an event-handler like notify to react on any new "smoke" update. But for this, further info would be required.
Server: HP-T5740 mit Debian stretch (i386) + aktuellem FHEM | ConfigDB | CUL_HM: div. Hardware mit VCCU | MySensors seriell (2.3.1@RS485, daran div. Sensoren usw., u.a. DS18B20) | Milight@ESP-GW@MQTT2 | zigbee2mqtt@MQTT2 | SIGNALduino | MapleCUN