I have OpenHab 2 working with MQTT and a growing MySensors network. For a couple of my the sensors, it would be good if I could synchronize the time. MySensors has a method to request the time from the controller. The value passed back to the sensor should be a Unix timestamp. I think I can figure out the rule to respond to a given MQTT request from the sensor and send out the response, but I can’t figure out how to calculate the value for the response.
I can get the UTC Unix Epoch with:
var n = now
var e = n.getMillis
but then adjusting this for my timezone and adjusting for DST is where I am stuck.
If full java classes are allowed you could use Calendar.getInstance().getTimeInMillis(). The calendar class is quite sophisticated and considers timezones etc and allows manual adjustment with addHour().
I don’t think this makes sense. The number of seconds since January 1 1970 is an absolute measure that will not change with the timezone. The representation as local time, however, will change, but as I understand it that is not what you are after?