Share your scripts

As it happened that something was blocking the fridge door a couple of times recently, I added a window/door sensor to it and created this script to notify all notification devices when it’s left open for more than a minute. That is, in my case to the mobile devices of all family members and a notification popup on the TV running Kodi.

Thought I’d share it for inspiration to others. Would be nice if you guys could share some of yours too.

import QtQuick 2.0
import nymea 1.0

Item {
    ThingState {
        id: fridge
        thingId: "{7fa11a09-1370-43e4-bfdc-d8b5260cc6cf}" // Fridge
        stateName: "closed"
    }
    
    Timer {
        interval: 60000
        running: fridge.value == false
        repeat: false
        onTriggered: {
            for (var i= 0; i < notifications.count; i++) {
                var thing = notifications.get(i)
                thing.executeAction("notify", {"title": "Warning", "body": "Fridge is open!"})
            }
        }
    }
    
    Things {
        id: notifications
        filterInterface: "notifications"
    }    
}

This short script is running on my system, which sends a push notification to my phone in case any of my water detecting sensors reports water and tells me which one it actually is.

The same can be applied to all kind of sensors like smoke/fire sensors or low batterie devices, if you change the script accordingly. Thank you @mzanetti for your help setting this up and maybe this is helpful for others, too

import QtQuick 2.0
import nymea 1.0

Item {
    InterfaceState {
        interfaceName: "watersensor"
        stateName: "waterDetected"
        onStateChanged: {
            if (value == true) {
                var thing = myThings.getThing(thingId)
                var title = "Water detected"
                var body = "%1 reports water".arg(thing.name)
                notificationThing.executeAction("notify", {title: title, body: body})
            }
        }
    }
    
    Things {
        id: myThings
    }
    
    Thing {
        id: notificationThing
        thingId: "{}" // your push notification thing
        
    }
}
1 Like