You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone, for a retained mqtt topic i can use %deviceName% or %roomName% as dynamic variables - is there a %timestamp% tag or any other way to publish the timestamp of the last on/off toggle?
cheers
The text was updated successfully, but these errors were encountered:
I have implemented the following in /opt/z-way-server/automation/userModules/MQTT/index.js. Now the mqtt publishes a JSON with a timestamp and the value instead of string "on" or "off" only
//function added for leading zero
MQTT.prototype.trimString = function( txt, len ) {
if( txt.toString().length==1 ) return "0" + txt.toString();
return txt;
};
//updated function publish
MQTT.prototype.publish = function (topic, value, retained) {
var self = this;
if( self.client && self.client.connected) {
var options = {};
options.retain = retained;
var dt = new Date();
var dtString = dt.getFullYear() + "/" + self.trimString( dt.getMonth()+1, 2 ) + "/" + self.trimString( dt.getDate(), 2 );
dtString += " " + self.trimString( dt.getHours(), 2 ) + ":" + self.trimString( dt.getMinutes(), 2 ) + ":" + self.trimString( dt.getSeconds(), 2 );
var value_publish = '{"ts":"' + dtString + '","value":"' + value + '"}';
self.client.publish( topic, value_publish.toString().trim(), options );
}
};
Hi everyone, for a retained mqtt topic i can use %deviceName% or %roomName% as dynamic variables - is there a %timestamp% tag or any other way to publish the timestamp of the last on/off toggle?
cheers
The text was updated successfully, but these errors were encountered: