node-zwave-js icon indicating copy to clipboard operation
node-zwave-js copied to clipboard

Make dateTime valueId more intuitive

Open robertsLando opened this issue 2 years ago • 8 comments

Ref: https://github.com/zwave-js/zwavejs2mqtt/discussions/2277

robertsLando avatar Feb 21 '22 09:02 robertsLando

I don't see how this is an enhancement. It looks like a bug to me. At the moment I don't think there is any way to set dateAndTime from the GUI, as the backend expects a Date object.

stridger avatar Mar 19 '22 11:03 stridger

@AlCalzone Let you add the correct labels to this issue

robertsLando avatar Mar 21 '22 08:03 robertsLando

Honestly, I don't care about the label. The issue exists and should be worked on at some point.

AlCalzone avatar Mar 21 '22 08:03 AlCalzone

Can I just add that this is not about the field becoming more intuitive, it is about making the field usable in any way at all. There is currently no way to set the times of the devices which support the 0x8b Time Parameters command class. Not via the API or in any other way apart from reinterviewing the device. Reinterviewing runs the time setting by itself, but the fact that the dateAndTime parameter requires a Date object, which cannot be serialised makes the command class API completely unusable.

stridger avatar Apr 04 '22 12:04 stridger

If you use the API in a way the doesn't require serialization, e.g. the driver function, it does work.

AlCalzone avatar Apr 04 '22 13:04 AlCalzone

Fair enough. sorry for phrasing that incorrectly. I guess there is just no way to set it in home assistant, as the driver function is not exposed to Python? At least I couldn't find how to get that to work. I could of course do a full-fledged Python app importing the right ZWaveJS libraries etc, but that seems overkill to me. So if there is a simple way of using that, then please let me know. Currently all possible ways I have investigated eg via ZWaveJS2MQTT API, or via the HA API etc, all seem to require serialisation.

stridger avatar Apr 04 '22 13:04 stridger

I'm not sure what HA exposes how, but if you have access to the MQTT API, you can execute this function. Granted this seems unnecessary complicated, but should work: https://zwave-js.github.io/zwavejs2mqtt/#/guide/mqtt?id=z-wave-apis https://zwave-js.github.io/zwavejs2mqtt/#/guide/mqtt?id=api-call-examples

Set the topic <mqtt_prefix>/_CLIENTS/ZWAVE_GATEWAY-<mqtt_name>/api/driverFunction/set with the following payload:

{
	"args": [
		"const node = driver.controller.nodes.get(35); await node.commandClasses['Time Parameters'].set( new Date(2020, 3, 4, 12, 34, 56) );"
	]
}

Replace 35 with your node ID.

The Date constructor takes the following arguments: year, month, day, hour, minute, second, (optional ms), or one of the other variants: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date Note that month is 0-based, so 3 = April.

AlCalzone avatar Apr 04 '22 14:04 AlCalzone

Excellent, thank you so much. After @robertsLando gave me that hint in a separate feature request I was already doing it that way but could not get the syntax right, as I was doing it via the TimeParametersCCSet function and could not get it to work quite right. But yours seems to work perfectly (I still have to check whether it actually executes on the device, but I don't see why it shouldn't). So to set the current date and time I thus used

{
  "args": ["const node = driver.controller.nodes.get(12); await node.commandClasses['Time Parameters'].set( new Date() );"]
}

Thank you both for all your work on this and for helping me out!

stridger avatar Apr 04 '22 15:04 stridger