Magic rule with hue motion sensor help

Hi there,

New Nymea user here. I am trying to set up two magic rules involving a hue motion sensor and a hue smart plug that works like this:

  1. [If present] then turn on hue smart plug
  2. [If last “Last Seen Time” is greater than 5 minutes compared to present time] then turn off hue smart plug

What I want to achieve is that something turns on when I walk into a room, and that the something turns off again 5 minutes after I left the room.

The first rule works fine. For the second rule the closest I have come is to use the option in the app to set “Last seen time” is less than or equal to “0 + datetime”. Instead of zero I have tried to use a negative value, hoping the value there would be in seconds…but to no avail.

Does Nymea support what I wish to achieve, and if so what values or rules can be used?

Thanks in advance for all help :slight_smile:

Solved by creating a script

import QtQuick 2.0
import nymea 1.0

Item {
    property int timeoutDuration: 300  // In seconds

    Thing {
    id: pluggyplugg
    thingId: "{power socket id}" // Power socket 
    }

   ThingState {
   id: lastSeenTime
   thingId: "{motion sensor id}" // Motion sensor
   stateName: "lastSeenTime"
   }
   
   Timer {
   id: motionTimeoutTimer
   interval: 3 * 1000  // 30s in ms
   running: true
   repeat: true
   onTriggered: {
        // Check if the motion sensor hasn't detected movement for timeoutDuration
        if (new Date().getTime() - (lastSeenTime.value * 1000) > timeoutDuration * 1000) {
                pluggyplugg.setStateValue("power", false)
            }
        }
    }
}
2 Likes

Hi @lahansen, obviously you helped yourself pretty well. :slight_smile: Welcome to nymea!

1 Like