Lock.set_usercode script not working (manually working fine)

Hi All,

Working on an automation to generate a random 4 digit pin and set my lock code for my door. Here’s the script:

housekeeper_code_on:
  sequence:
    - service: lock.set_usercode
      data_template:
        node_id: 44
        code_slot: 4
        usercode: states.sensor.pin_code.state
    - service: notify.twilio_sms
      data:
        message: "You can use the code {{ states.sensor.pin_code.state }} to get into the house today"
        target:
          - !secret cell_phone
    - service: notify.slack
      data:
        message: "Housekeeper code has been enabled! Code is: {{ states.sensor.pin_code.state }}"

It is firing correctly, however the lock code never changes.

The locks are working fine, so if I go to Dev Tools -> States and fire off the command

Domain: lock
Service: set_usercode
Service Data: {“node_id”: “44”, “code_slot”: “4”, “usercode”: “1234”}

The locks change the code, so I suspect that it is just some syntax thing. Also, states.sensor.pin_code.state comes across correctly…so, I’m not sure what the problem could be. Anyone have any thoughts?

Thanks!

Chris

Ok, I figured it out…seems I need a combo of “data” and “data_template”.

script:
  housekeeper_code_on:
    sequence:
      - service: lock.set_usercode
        data:
          node_id: 44
          code_slot: 4
        data_template:
          usercode: "{{states.sensor.pin_code.state}}"
      - service: notify.twilio_sms
        data:
          message: "Good Morning!  You can use the code {{ states.sensor.pin_code.state }} to get into the house today"
          target:
            - !secret chris_mobile_num
      - service: notify.slack
        data:
          message: "Housekeeper code has been enabled! Code is: {{ states.sensor.pin_code.state }}"

What kind of lock is this?

Kwikset 910 Z-Wave

1 Like

I am a noob to HA with the exact use case. Would you mind providing a little more detail? Where did the script go and are there other automations / customizations needed to make it work?

I’d love a little more detail on this as well. Seems pretty close to what I’m looking to do for my house keeper.

Do you have another script that deletes the code after a specific amount of time?

How does

data_template:
          usercode:

work? Random code generator of some sort?

Thanks!

1 Like