Zwave_js event automation

Hi

I’m trying to figure out how to get the unlocking user registerd after upgrading to zwave.js.
While listening to zwave_js_event i get this response. How can i use this in an template to set who the user is?

"event_type": "zwave_js_event",
"data": {
    "type": "notification",
    "domain": "zwave_js",
    "node_id": 35,
    "home_id": xxxxxxxxx,
    "device_id": "xxxxxxxxxxxxxx",
    "label": "Keypad unlock operation",
    "parameters": {
        "userId": 5 <==== The user i want ==========
    }
}

In openZwave i got this with a sensor from the lock and this code:

{% set mapper = {
  '0':'Master',
  '1':'User1',
  '2':'User2',
  '3':'User3',
  '4':'User4',
  '5':'User5'} %}
{% set selection = trigger.event.data') %}
{{ mapper[selection] if selection in mapper else 'error' }}

Great thanks in advanced
Andreas

try changing

trigger.event.data

to

trigger.event.data['parameters']['userId']

Hi and thanks for your answer!
Just like this or am i missing something?

{% set mapper = {
  '0':'Master',
  '1':'User1',
  '2':'User2',
  '3':'User3',
  '4':'User4',
  '5':'User5'} %}
{% set selection = "trigger.event.data['parameters']['userId']" %}
{{ mapper[selection] if selection in mapper else 'error' }}

/Andreas

no double quotes around the trigger.xxxx part, otherwise it should be fine.

I’ll try that! Thanks

This works:

{% set mapper = {
  0:'Master',
  1:'User1',
  2:'User2',
  3:'User3',
  4:'User4',
  5:'User5'} %}
{% set selection = trigger.event.data.parameters["userId"] %}
{{ mapper[selection] if selection in mapper else 'error' }}
1 Like

I’m sorry but I’m confused with this. I am moving from automations that took the friendly name from the binary_sensor that the lock code triggered…. Are you putting this map in an automation and replacing the name? Like:

message: “{{mapper}}’s key unlocked the front door”

Could I please see your action section of an automation because I’m having trouble figuring out how to lay this out in my message template.

EDIT: Nvm, I think I got it… I’ll update with the code when I’m done thanks… I’m not sure why I was confused anymore… :grimacing:

Lol that’s exactly what I suggested and now you give the solution to someone else xD whatever floats your boat…

Hi, it was not my intention to make U upset. But with your suggestion it didn’t work, this due to small difference. So I thank you for your help in the right direction.

/Andreas

I’m not upset.
But I’m 100% sure that my suggestion is correct, it’s equivalent to the one you marked as a solution.
You put some double quotes around it yourself, which made it not work.

The difference that made it work is that parameters is without [ ] and that the numbers that give user is without single quotes. So my double quotes had nothing to do with it. The only thing I did with mark as solution is that I wanted to show what suggestion that worked for me.

1 Like

No, that’s not true, as I said, they are equivalent:

They for sure did, when you put double quotes around it, it will be interpreted as a string:

That’s correct, I didn’t notice that one.

Thanks for your feedback, I now understand this form of template a little better. My automation now work as intended and I’m happy with that. Thank you for your help.
/Andreas

Are you able to post your automation. Wouldn’t mind seeing the complete solution.

2 Likes