Kwikset lock codes

Sorry still having a difficult time figuring it out. Basically want user code 2 to send http.

Can you share more details about what you’ve tried so far?

The first link in my reply above has more details and an example rule screenshot.



This is what I had on webcore

I am using the "Alexa Multi-trigger " device in ST to enable sending the info to Alexa:
image

I have a variable set up in Sharptools to set the $User variable depending on the code from the lock:
image

I have a rule in Sharptools that checks the codename sent from the lock: $context.event.data.codeName

Based on the value in $User I turn on the appropriate Alexa Multi-trigger switch in my rule:

Then in Alexa I announce “Welcome Home…” if the switch is turned on:

I suppose there may be other ways (and maybe simpler) of doing this, but this is what I was able to figure out on my own and it works for me.

1 Like

Why type of variable. Text number

Antonio Stifano

Thanks for sharing, @John_Kelton !

As John demonstrated with his rule and as shown in your WebCoRE example, you would normally want to trigger off the door lock attribute changing to unlocked

In John’s case, it looks like he has named each of the codes, so he’s accessing the codeName within the extra event data, but if you want the codeId, you would adjust your rule accordingly.

Here’s a video showing how to set it up. I originally intended this as a brief video, but I guess I got a bit carried away showing a few approaches!

1 Like

I don’t see the context.event.

Antonio Stifano

I see that you’re replying via email. Make sure to check the video included in my last reply which walks through the whole process end to end…

Thanks. I will try and figure it out that way.

I got that working.
However I was working on another rule with the lock. Just wanted when any code was pressed it would turn on a light between sunset and sundown. However light turns on all the time and the lock doesn’t work
properly. It will trigger the light even unlocking manually.




Thanks for sharing the screenshots. The rule in your screenshots doesn’t appear to be configured that way.

I would strongly recommend reading through some of the documentation on the Rule Engine as that will give you a good understanding of the fundamentals of how rules work in SharpTools:

Keep in mind that rules are triggered when any of the configured trigger events occur. So in your case, the rule will run at 10 minutes after sunset, then again 10 minutes before sunrise, and anytime the Back Door lock attribute value changes.

When the rule is triggered, it will execute the Rule Flow from top-to-bottom.

So the first action that sets the variable $Code won’t work as expected with the sunset and sunrise trigger since those won’t have a $context.event.data.Method. (Furthermore, you may need to use the lowercase method instead of Method unless your lock reports that value in a non-standard way).

Then when the IF Condition block is hit, the rule will check if that Lamp switch is off or the time is after Sunset or the time is before sunrise or the $Code is Keypad. When any of those conditions are true, it will proceed to the then path and take the actions you’ve configured. Keep in mind that you can edit the IF Condition block and change it to AND instead of OR.

So you’ll want to make sure that the conditions are configured as you would expect and make sure to adjust them accordingly - I suspect you wanted to AND some of the conditions together and perhaps nest a condition for before sunrise or after sunset. Similar to the capitalization of the data attribute name mentioned above, you’ll want to double check that the reported value is correct as it’s usually a lowercase keypad.

PS. For future reference, you can use the Rule Screenshot feature to get a single screenshot for the whole rule that is easier to share.

Thank you.

Antonio Stifano

I have been reading posts. I haven’t seen anything with locks and time. I have tried trigger with sunset and sunrise. I have tried if commands with sunset and sunrise. Doesn’t seem to work. If I remove the sunset and sunrise the rule works. Not sure if I can use time with locks.

I think I figured it out

There’s no restrictions around using time with locks.

If I understand what you are looking for correctly, you would want to remove the sunset/sunrise triggers, then use a nested condition for the time.

Triggers

'Back Door - lock' changes to 'unlocked'

Flow

IF '$context.event.data.method' is 'keypad'
   AND 'Lamp - switch' is 'off'
THEN
   IF 'Current Time' is before 'Sunrise'
      OR 'Current Time' is after 'Sunset'
   THEN
      Command: 'Lamp' 'on()'
      Delay '600 seconds'
      Command 'Lamp' 'off()'

Pay particular attention to the use of OR vs AND conditions in the example above and the use of nesting.

The logic above would say that anytime the Back Door is unlocked, we should run the flow. If the method that was used to unlock was keypad and the lamp is currently off, then run the nested condition to check if the time is before sunrise or after sunset. Only if both sets of conditions are true, then the innermost set of commands would run to turn the light on, wait 600 seconds, then turn it back off.

Why nested conditions?

The reason we are using nested conditions here is you want to mix AND logic with OR logic. So in the outer condition, we have all of the conditions that we need to AND together (eg. unlocked with keypad and the light is off). Then only if that’s true will it check the nested IF condition.

And we need to use an OR condition with the time as we want the rule to continue to run when it’s either before sunrise or after sunset… and since we want to mix that with two conditions that must both be true (eg. AND), we use a separate condition for those.

Other Thoughts

Keep in mind that this kind of logic where you turn something on, wait, then turn it back off can also be tricky.

If the door gets unlocked multiple times in a short period of time, you’ll have two executions of the rule running.

So the first will turn the light on and start waiting 10 minutes. Then if another occurs within the 10 minutes, it will turn the light on (no effect since it’s already on) and start waiting 10 minutes.

But the timer from the first run would hit first and turn the lamp off before the second timer hits.

t0                      t10
on() →    wait(10m)   → off()
                          ^
     t1                   |   t11
     on() →    wait(10m)  | → off()
                          |
                          |
//The light gets turned off at t10 from the first execution
// which is 1 minute short of when you might have expected
// it to turn off based on the second execution

That looks close. You’ll likely want to use an OR condition in the nested condition though.

Tap the ‘Edit’ button at the bottom of the IF Condition block, then scroll up to the top of the IF Condition block and change from ‘all’ (AND) to ‘any’ (OR), then save the IF condition block.

Thanks. It’s working

Antonio Stifano

The rules were working fine. But now just stopped working. Getting errors on if from log.


Not sure if this helps, but when the variable ‘$User’ is showing red, I think it means it has been deleted; it should be blue.

1 Like

Thank you.

Antonio Stifano