OpenHab run on a server that may be used without access to internet. It reads an energy meter with an ESP8266 microcontroller that reports meter values via mqtt over wifi. Each hour the meter reports accurate time in a string (“yyyy-mm-dd hh:mm:ss”). The following rule in meant to set the system time based on this string.
- Platform information:
- RPi with openhabian and openHAB 2.5.0~S1549-1 (Build #1549)
- Rules code related to the issue
rule "Update clock from meter" when Item PW_hourStamp changed then logInfo("Clock updated to:", "" + PW_hourStamp.state) var String hourStamp = "'" + PW_hourStamp.state +"'" val String results = executeCommandLine("sudo date --set " + hourStamp) logInfo("Error from update is", "" + results) end
Output from testing the rule:
2020-01-01 13:48:38.308 [INFO ] [thome.model.script.Clock updated to:] - 2020-01-01 13:00:10 2020-01-01 13:48:38.377 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'sudo date --set '2020-01-01 13:00:10'' 2020-01-01 13:48:39.683 [INFO ] [me.model.script.Error from update is] - null
Using sudo does not seem to work. Omitting the sudo makes the following output:
2020-01-01 13:52:02.531 [INFO ] [thome.model.script.Clock updated to:] - 2020-01-01 13:00:10 2020-01-01 13:52:02.542 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'date --set '2020-01-01 13:00:10'' 2020-01-01 13:52:02.544 [INFO ] [me.model.script.Error from update is] - null
Is there a better way to update the system time from a rule?
I would appreciate any advice that points me to in the right direction
Best regards Per