I have an smoke device, and I want to publish the state and time with mqtt
I have this
fhem> l Rookzolder
Internals:
IODev mqtt
NAME Rookzolder
NR 102
STATE Clear
TYPE MQTT_DEVICE
READINGS:
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
message_ids:
sets:
subscribe:
zigbee2mqtt/smokezolder
subscribeExpr:
^zigbee2mqtt\/smokezolder$
subscribeQos:
zigbee2mqtt/smokezolder 0
subscribeReadings:
zigbee2mqtt/smokezolder:
cmd
name rook
Attributes:
IODev mqtt
eventMap 0:Clear 1:Fire
room Zolder
stateFormat smoke
subscribeReading_rook zigbee2mqtt/smokezolder
and a publish
fhem> l rookzolder_mqtt
Internals:
DEF Rookzolder
IODev mqtt
NAME rookzolder_mqtt
NOTIFYDEV Rookzolder
NR 106
NTFY_ORDER 50-rookzolder_mqtt
STATE outgoing publish sent
TYPE MQTT_BRIDGE
READINGS:
2018-07-09 17:54:49 transmission-state outgoing publish sent
message_ids:
publishReadings:
smoke /zigbee2mqtt/smoke1
subscribe:
subscribeExpr:
subscribeQos:
Attributes:
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
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.