Author Topic: schlage automation based on what pin code is entered  (Read 304 times)

Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
schlage automation based on what pin code is entered
« on: August 08, 2017, 07:32:30 pm »
Hello all. I am trying to have my schlage BE469NX turn on my kitchen lights when i enter a specific pin code at night/when its dark if the light is not already on.  i have tried using blocky in rules engine but cant gt it to go any help would be appreciated.

Online jswim788

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +15/-2
Re: schlage automation based on what pin code is entered
« Reply #1 on: August 08, 2017, 08:18:51 pm »
Create a scene that has the trigger with the specific pin code.  Have the scene turn on the light.  Then, in the scene's luup, put this:
Code: [Select]
return luup.is_night()See this post for lots of information on conditional scenes: http://forum.micasaverde.com/index.php?topic=18679.0

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9499
  • Karma: +721/-133
    • RTS Services Plugins
Re: schlage automation based on what pin code is entered
« Reply #2 on: August 08, 2017, 10:10:24 pm »
You can also do it in PLEG.

Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: schlage automation based on what pin code is entered
« Reply #3 on: August 09, 2017, 09:14:19 am »
Create a scene that has the trigger with the specific pin code.  Have the scene turn on the light.  Then, in the scene's luup, put this:
Code: [Select]
return luup.is_night()See this post for lots of information on conditional scenes: http://forum.micasaverde.com/index.php?topic=18679.0
thanks for the life of me i did not see pincode as a trigger under vera regular scene creation.

Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: schlage automation based on what pin code is entered
« Reply #4 on: August 09, 2017, 09:18:52 am »
You can also do it in PLEG.
will look into as i  would also like to add some and or conditions.

Online jswim788

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +15/-2
Re: schlage automation based on what pin code is entered
« Reply #5 on: August 09, 2017, 12:26:31 pm »
thanks for the life of me i did not see pincode as a trigger under vera regular scene creation.

Should be there.  I use UI5 so I can't walk you through the steps, but you should be able to select the lock as the device for the trigger, then select the pin codes.  Perhaps it moved to an 'advanced' tab in UI7?

I've attached a snippet of the trigger that I set in UI5.

Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: schlage automation based on what pin code is entered
« Reply #6 on: August 09, 2017, 12:49:32 pm »
thanks for the life of me i did not see pincode as a trigger under vera regular scene creation.

Should be there.  I use UI5 so I can't walk you through the steps, but you should be able to select the lock as the device for the trigger, then select the pin codes.  Perhaps it moved to an 'advanced' tab in UI7?

I've attached a snippet of the trigger that I set in UI5.
I saw it but how can i create that scene and add  if the lights is already on/dimmed  dont make an changes to the lights.
 when i also select pincode my option = # 1 (Code 1) and i see you just put 4   in the box, so what format should i be using the default # 1 (Code 1) or just the 1 with no # sign
« Last Edit: August 09, 2017, 12:57:51 pm by stress1ner »

Online jswim788

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +15/-2
Re: schlage automation based on what pin code is entered
« Reply #7 on: August 09, 2017, 01:04:57 pm »
I saw it but how can i create that scene and add  if the lights is already on/dimmed  dont make an changes to the lights.

First suggestion: if the light is on, turning it on again shouldn't matter.  So in the simple case you shouldn't have to do anything additional.

If the dimming value can be different and you want to preserve that, then it is a little more complicated, but not too hard.  You could use the function that Rex posted on checking the switch.  You need to fill in your Device ID for the switch.

Code: [Select]
function checkSwitch(dID, allow)
     --local dID = 66           -- Device ID of your Z-Wave Switch
     --local allow = true       -- true runs scene if switch is on, false blocks it
     local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
     return ((status == "1") == allow)
 end

So put the above in your scene code and put this after it:

Code: [Select]
return (luup.is_night() and checkSwitch(<your switch device ID here>, false))
that says run the scene if it is night and the switch is off.

Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: schlage automation based on what pin code is entered
« Reply #8 on: August 09, 2017, 02:04:54 pm »
I saw it but how can i create that scene and add  if the lights is already on/dimmed  dont make an changes to the lights.

First suggestion: if the light is on, turning it on again shouldn't matter.  So in the simple case you shouldn't have to do anything additional.

If the dimming value can be different and you want to preserve that, then it is a little more complicated, but not too hard.  You could use the function that Rex posted on checking the switch.  You need to fill in your Device ID for the switch.

Code: [Select]
function checkSwitch(dID, allow)
     --local dID = 66           -- Device ID of your Z-Wave Switch
     --local allow = true       -- true runs scene if switch is on, false blocks it
     local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
     return ((status == "1") == allow)
 end

So put the above in your scene code and put this after it:

Code: [Select]
so that says if  devices 66 is on  run the scene, in my case would I change the return ((status == "0") == allow) which would mean if the device/light i want to turn on is off then run the scene? and when you say  put the first part in the scene code and then put(luup.is_night() and checkSwitch(<your switch device ID here>, false)) after it, do you mean in the same luup block right.  Thanks for all your help also.
return (luup.is_night() and checkSwitch(<your switch device ID here>, false))

that says run the scene if it is night and the switch is off.


Online jswim788

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +15/-2
Re: schlage automation based on what pin code is entered
« Reply #9 on: August 09, 2017, 02:31:09 pm »
I had to fish out your question, it got lost in the code:
Quote
so that says if  devices 66 is on  run the scene, in my case would I change the return ((status == "0") == allow) which would mean if the device/light i want to turn on is off then run the scene? and when you say  put the first part in the scene code and then put(luup.is_night() and checkSwitch(<your switch device ID here>, false)) after it, do you mean in the same luup block right.  Thanks for all your help also.

Yes, same block.  And you don't need to fiddle with changing the return - you are passing the check through the function.  It has two arguments, the device ID, and the allow.  Since I set it to false in the call, it will return true if the light is off.  So the net result is that the end return will return true only if it is night and the light is off.  Assume the device ID is 66, then you need this in your scene code:
Code: [Select]
function checkSwitch(dID, allow)
     --local dID = 66           -- Device ID of your Z-Wave Switch
     --local allow = true       -- true runs scene if switch is on, false blocks it
     local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
     return ((status == "1") == allow)
end

return (luup.is_night() and checkSwitch(66, false))

One more thing: paste this into the test code window and run it there to test it.  You'll want to see that it "fails" when it is not night and when the light is on, and should "pass" when it is night and the light is off.


Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: schlage automation based on what pin code is entered
« Reply #10 on: August 09, 2017, 02:50:35 pm »
Ok thanks much appreciated as i was trying to use rules engine to do this. Would i just use commas with the devices id number if i wanted it to check if additional devices are on.

Online jswim788

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +15/-2
Re: schlage automation based on what pin code is entered
« Reply #11 on: August 09, 2017, 02:53:43 pm »
Ok thanks much appreciated as i was trying to use rules engine to do this. Would i just use commas with the devices id number if i wanted it to check if additional devices are on.
You'd need to check each device.  Here's an example of 2 devices with ID's 66 and 67.  Change the last line to this:
Code: [Select]
return (luup.is_night() and checkSwitch(66, false) and checkSwitch(67, false))

Offline stress1ner

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: schlage automation based on what pin code is entered
« Reply #12 on: August 09, 2017, 04:12:59 pm »
Ok thanks much appreciated as i was trying to use rules engine to do this. Would i just use commas with the devices id number if i wanted it to check if additional devices are on.
You'd need to check each device.  Here's an example of 2 devices with ID's 66 and 67.  Change the last line to this:
Code: [Select]
return (luup.is_night() and checkSwitch(66, false) and checkSwitch(67, false))
thank you.

Offline Priest

  • Full Member
  • ***
  • Posts: 101
  • Karma: +4/-0
Re: schlage automation based on what pin code is entered
« Reply #13 on: August 09, 2017, 06:55:21 pm »
Would this be an appropriate variation to check to see if the dimmer is above 5% or not?  So, if the dimmer is 0-5 then the scene will run...if it is 6-100 then the scene will not run.

Or am i still code stupid?

Quote
function checkSwitch(dID, allow)
     --local dID = 23           -- Device ID of your Z-Wave Switch
     --local allow = true       -- true runs scene if switch is on, false blocks it
     local level = tonumber(luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",dID),10)
     return ((level >5) == allow)
end

return (luup.is_night() and checkSwitch(23, false))

Online jswim788

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +15/-2
Re: schlage automation based on what pin code is entered
« Reply #14 on: August 09, 2017, 07:28:14 pm »
I'm not 100% sure of this, but you may have a problem with the variable_get returning 2 values.  Then you'll be feeding 3 parameters into tonumber() which only wants 2.  This should work:
Code: [Select]
local level = tonumber((luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",dID)))the extra parentheses force one return value, and the default of the tonumber is base 10, so you don't need to specify it.

By the way, you kind of have negative logic.  If you want it to run when dimmer is below 6, I'd test for that condition as the code is easier to follow.  So something like this:
Code: [Select]
function checkSwitch(dID, allow)
     local level = tonumber((luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",dID)))
     return ((level < 6) == allow)
end

return (luup.is_night() and checkSwitch(23, true))

Also, you don't even need the function if you are just checking one light - this was just an example.  So even simpler:
Code: [Select]
local level = tonumber((luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",23)))
return ((level < 6) and luup.is_night())