Help with my first lua code snippet

I know this may sound very easy but this is my first time programming with lua.

Scenario:

I have a tilt sensor on my garage door. The device ID for the tilt sensor is #6
Device Type: urn:schemas-micasaverde-com:device:MotionSensor:1

I have a scene called “Open/Close Garage Door” - scene #4

As of now, I can open and close the garage door and see its status, but I want to create a new scene that will CLOSE the garage door IF it is open.

I have tried a lot of different code with no luck. Here is the code I am currently working with.

if( luup.variable_get(“urn:upnp-org:serviceId:MotionSensor:1”,“Tripped”,6)==“1” ) then

luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = “4”}, 0)

return true

end

Any help would be GREATLY appreciated!!!

I actually got this working.

There were two problems with my code above.

  • I needed to use SecuritySensor1 instead of MotionSensor1
  • I had the wrong ID for the sensor (I used the altID by mistake in my previous code)

The working code if anyone is interested is below:

if( luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Tripped”,23)==“1” ) then

luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = “4”}, 0)

end

You would not want it to close anytime it is open. Specific time. Make sure your auto reverse is adjusted properly, and you should have a safety sensor that looks across the door at the bottom.

Sent from my iPad using Tapatalk