I’m using a low cost AC power meter which requires the following command to reset the “energy” counter. Slave address + 0x42 + CRC high + CRC low.
Is there a way to send such a command executed by a button? I could not figure it out using the docs or google.
Reading values works fine. Here is the configuration for the .things file I use:
Bridge modbus:serial:ext_power_sensor_230v [ port="/dev/ttyMODBUS2", baud=9600, stopBits="1.0", parity="none", dataBits=8, encoding="rtu", id=1] {
Bridge poller input [ start=0, length=10, refresh=2500, type="input" ] {
Thing data voltage [ readStart="0", readValueType="uint16", readTransform="JS(divide_by_10.js)" ]
Thing data current [ readStart="1", readValueType="uint32_swap", readTransform="JS(divide_by_2000.js)" ]
Thing data power [ readStart="3", readValueType="uint32_swap", readTransform="JS(divide_by_20.js)" ]
Thing data energy [ readStart="5", readValueType="uint32_swap", readTransform="JS(divide_by_2.js)" ]
Thing data frequency [ readStart="7", readValueType="uint16", readTransform="JS(divide_by_10.js)" ]
Thing data power_factor [ readStart="8", readValueType="uint16", readTransform="JS(divide_by_100.js)" ]
Thing data alarm_status [ readStart="9", readValueType="uint16" ]
}
}
[ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler@1d07e51': null
java.lang.NullPointerException: null
at org.openhab.core.io.transport.modbus.json.WriteRequestJsonUtilities.constructBluerint(WriteRequestJsonUtilities.java:125) ~[?:?]
at org.openhab.core.io.transport.modbus.json.WriteRequestJsonUtilities.lambda$0(WriteRequestJsonUtilities.java:103) ~[?:?]
at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
at org.openhab.core.io.transport.modbus.json.WriteRequestJsonUtilities.fromJson(WriteRequestJsonUtilities.java:102) ~[?:?]
at org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler.processJsonTransform(ModbusDataThingHandler.java:308) ~[?:?]
at org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler.transformCommandAndProcessJSON(ModbusDataThingHandler.java:242) ~[?:?]
at org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler.handleCommand(ModbusDataThingHandler.java:188) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
at org.openhab.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]
at com.sun.proxy.$Proxy225.handleCommand(Unknown Source) [?:?]
at org.openhab.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:80) [bundleFile:?]
at org.openhab.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:48) [bundleFile:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
I would like to count the used energy over a given time. Like monthly or daily.
Since the sensor has the API I tried to use it but if it’s not trivial to solve I work around it by buffering the start value and calculate the difference after a given time.
If you have a persistence service running, you could just log the accumulated value each day. To find usage over a period, query the start and end values and calculate the difference. There might even be a way to do that directly in the database query.
The advantage of this method is you aren’t tied to a single reset schedule, you can always query between any two readings.