myhouse-project / myHouse

Home monitoring and automation suite with interactive Slack bot
GNU General Public License v3.0
2 stars 0 forks source link

How can I create a rule based on the last time a sensor reported to myHouse? #304

Closed user2684 closed 5 years ago

user2684 commented 7 years ago

Reported by: rmtucker63

Having looked over this section in the wiki and How can I configure a rule to trigger only once?. I gave up trying to implement this on my setup. The first part can of course be done using placeholders so one rule covers all sensors,but this of course would then trigger every minute as you rightly state. But i think some method of How can I configure a rule to trigger only once? also needs some method using place holders otherwise i have to create lots of versions of the rule and lots of dummy sensors to handle it as in your example.

user2684 commented 7 years ago

Original comment by: user2684

Yeah this is something I was looking at but pretty challenging to implement so I postponed it but would make sense to find a smart way to achieve this. A temporary workaround could be to still create all the dummy sensors you need and use a single rule with a "for" so you can have the placeholder %i% replaced. I use something similar for my alarm module where each sensor has a corresponding "armed" fummy sensor. Just in case it can help:

        {
          "rule_id": "alarm_24h",
          "for": [
            "alarm:sensors:fire_first_floor",
            "alarm:sensors:fire_ground_floor",
            "alarm:sensors:gas_first_floor"
          ],
          "display_name": {
            "en": "Alarm! The sensor %i% has triggered"
          },
          "enabled": true,
          "severity": "alert",
          "run_every": "minute",
          "conditions": [
            "sensor_armed == status_on",
            "sensor == status_on"
          ],
          "definitions": {
            "sensor_armed": "%i%_armed,-1,-1",
            "sensor": "%i%,-1,-1",
            "status_on": 1
          }
        },