ryanjohnsontv / node-red-contrib-ha-inovelli-manager

Nodes for easily managing scenes, parameters, and notifications of Inovelli switches paired through various Home Assistant integrations
MIT License
15 stars 3 forks source link

How to use node_id instead of entity_id? #63

Closed neilenns closed 1 year ago

neilenns commented 1 year ago

I'm trying to use the inovelli-notification-manager node to dynamically change the LED on the specific Inovelli switch that triggered the event. I can't figure out how to get the right data for the node however.

The node appears to require the entity_id, e.g. switch.office_light. But the events node I'm using to detect the light switch push in the first place only gives me a node_id, e.g. 37, not the switch name.

Is there any way to do this where either the incoming event has the entity_id or I can get the entity_id from a zwavejs node_id?

neilenns commented 1 year ago

Playing around with this a bit more it looks like device_id might work, as it comes in the zwavejs event, but the node doesn't support using device_id. When I try and send it in via msg.payload.device_id the resulting call-service API node throws an error:

must contain at least one of device_id, entity_id, area_id
neilenns commented 1 year ago

Ok I confirmed by manually setting the payload with an inject node that device_id will do the trick. Is it possible to update the nodes to support device_id? Here's the payload I used:

{
    "domain": "zwave_js",
    "service": "bulk_set_partial_config_parameters",
    "data":
    {
        "device_id": "c0edd47ff912f14b0941a0a1d24a14f4",
        "parameter": 8,
        "value": 34211077}
    }
}
ryanjohnsontv commented 1 year ago

Hey Neil! I appreciate you taking the time to dive into this. If I'm understanding your use case correctly, you're using the scene manager node to send events to the LED manager node for that same light switch? Assuming I understand that correctly, there is a bit of a gap in how Z-Wave JS integrate with Home Assistant. For instance event messages contain the node ID and device ID, however calling the zwave_js service doesn't allow the node ID. So I think adding the device ID to the scene manager to filter events will help, and then being able to call the zwave_js service using the device ID or area ID.

Right now for my home I have scene manager nodes for all my switches and their respective node IDs. I use the optional entity ID field to append it to each event message (ex: Office Light Switch is node 15, 1x up button press event for that switch is passed out the corresponding output with msg.entity_id set to "light.office_lamps" so I can reference that in my function nodes to set the lamps in the room to the proper brightness). I think there's definitely logic to allow the device ID to be used to simplify this so the ID used to filter the events node is passed, and for your use case that device ID can be referenced in the LED manager node to set parameters on the switch.

That was a long winded way of saying... this is a great feature request and I will try to have it merged in by end of day. I've had a local PR with a major rewrite and support for the Blue switches for a while, so I'll getting this added to that. Thank you!

neilenns commented 1 year ago

I think we converged on similar solutions 😊 I opened a draft PR with what I hacked up. Maybe it'll help with the changes you have locally.

In my situation I have one scene manager node responding to multiple switches. Any switch in the house that I press and hold will turn off all the lights. I want to flash the LED on the switch that was held so I know the press and hold was detected. Since there are multiple switches handled by the scene manager, currently there is no easy way to pass a device id or entity id to the notification manager node.

ryanjohnsontv commented 1 year ago

I have a function node that maps each entity ID to a node ID, area, and other parameters I use (ie. minimum brightness, transition time, default color temp) and stores that, as well as simpler generated maps that map a node ID to its entity ID. That runs every time I deploy my flow and stores it as flow/global variable I can access in my other nodes. Makes it very easy to design reusable flows. Might not be necessary for you once these changes are released but if you like working with function nodes, I highly recommend that approach!

neilenns commented 1 year ago

I considered doing that but really didn't like adding a function node and maintaining mapping table for data that already existed earlier in the flow 😬

ryanjohnsontv commented 1 year ago

I'm still working on migrating what you've done. Overall I think the whole thing needs more of a rewrite (like a table you can add and remove parameters from for LED manager) but I'm going to hold off to try and get this out ASAP. I like your implementation of using a scene event payload to create the target instead of a user-entered entity ID. https://github.com/ryanjohnsontv/node-red-contrib-ha-inovelli-manager/pull/66/files

jprasm commented 1 year ago

Hi guys, I've been following this thread (loosely), and I'm wondering if this helps you?

I found that I could create a change node that takes in the z-wave event, and then passed it to HA as a template to be processed, I could get the name from the device_ID, get the area, and then add additional data.

I am able to identify which inovelli switch is pressed in my house and how many taps, the area (if I want) etc. (I read this thread quickly, so if this is irrelevant to your case, please disregard).


[{"id":"d946ea0290780cc7","type":"link in","z":"7a48450ad19c27ab","g":"3e3cef3829cc1dfe","name":"Z-Wave Event: Device Identify","links":["0a811b4d82944bc9","0e4896a5792e3f7c","652b0feaa1c817e9","7f48ce82a768efba","a519fa93389c4053"],"x":770,"y":1371,"wires":[["8bfc70bf2465be86"]]},{"id":"8bfc70bf2465be86","type":"change","z":"7a48450ad19c27ab","g":"3e3cef3829cc1dfe","name":"","rules":[{"t":"set","p":"template","pt":"msg","to":"'{{device_attr(\"' & payload.event.device_id & '\",\"' & 'name'  &'\")}}' &\t \" Key \" & payload.event.property_key & \" Pressed \" & $substringAfter(payload.event.value,\"Pressed\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":916,"y":1371,"wires":[["cb7b85440b9abfeb"]]},{"id":"cb7b85440b9abfeb","type":"api-render-template","z":"7a48450ad19c27ab","g":"3e3cef3829cc1dfe","name":"","server":"181266bf.748f49","version":0,"template":"","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1099,"y":1371,"wires":[["c099a2d40e7fe6f2"]]},{"id":"181266bf.748f49","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!