Skip to content

Instantly share code, notes, and snippets.

@hacki11
Last active April 23, 2023 19:08
Show Gist options
  • Save hacki11/18735fcdc3ac75472ce5bcbf928b1449 to your computer and use it in GitHub Desktop.
Save hacki11/18735fcdc3ac75472ce5bcbf928b1449 to your computer and use it in GitHub Desktop.
Time Synchronization with HeishaMon
// define MQTT ID to set curves
const JeishaCurve = "mqtt.0.heishamon.commands.SetCurves";
// define MQTT ID for the Time Request Trigger
const JeishaTimeRequest = "mqtt.0.heishamon.main.Z1_Cool_Request_Temp";
// define MQTTT ID to acknowledge time transfer
const JeishaTimeResponse = "mqtt.0.heishamon.commands.SetZ1CoolRequestTemperature";
on({id: JeishaTimeRequest, val: 1}, function(obj) {
var date = new Date();
let encodedHour = encodeHour(date.getHours());
let encodedMinute = encodeMinute(date.getMinutes());
const curve = {
zone1: {
cool: {
target: {
low: encodedHour[0],
high: encodedHour[1]
},
outside: {
low: encodedMinute[0],
high: encodedMinute[1]
}
}
}
};
const curveString = JSON.stringify(curve);
log("Send current time to heishamon (" + curveString + ")");
setState(JeishaCurve, curveString);
log("Acknowledge time is written to Heishmon");
setState(JeishaTimeResponse, 2);
});
for(let i = 0; i < 24; i++) {
log("hour("+i+") := " + encodeHour(i));
}
for(let i = 0; i < 60; i++) {
log("minute("+i+") := " + encodeMinute(i));
}
function encodeHour(hour) {
const A = Math.trunc(hour / 12) + 6;
const B = 20 - hour % 12;
return [A, B]
}
function encodeMinute(minute) {
const C = Math.trunc(minute / 11) + 15
const D = 30 - minute % 11;
return [C, D]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment