There’s a few questions about how to get the value of Player channel states/commands as a string value, but it seems an MQTT Thing doesn’t publish these. The appear in debug/API as a plain text commands such as PREVIOUS, PLAY, PAUSE, NEXT etc. I have a player control set up next to a String value in a MQTT follow channel.
I’m also seeing a need to sync up the localised events in OpenHAB with the broker, as other MQTT clients will receive inaccurate message times if they are retained. They will be delivered like a flood and not reflect the actual time of the event.
Using the latest binding. The variable %t was just an arbitrary value to indicate a timestamp or datetime value which would be helpful to have in the binding if it’s not there already.
We can’t do all that on every OpenHAB instance just for a text string like we get with the others. Isn’t there an actual event sent from the channel?
You could subscribe to the broker to always add timestamps to mqtt messages.
You can skip using things and just use a MQTT action to sent message
Then it would look something like
rule "Player State to MQTT"
when
Item Tv received command
then
val timestamp = new DateTimeType()
val value = '{\"attribute\": \"player\", \"value\": \"' + receivedCommand + '\", \"timestamp\": \"' + timestamp + '\"}'
val actions = getActions("mqtt","mqtt:broker:myMQTTBroker") // myMQTTBroker is the name of my broker yours may be different
actions.publishMQTT("tv/player",value)
logInfo("publishMQTT", value )
end