State Node how to check if device still power on after another 5 min?

I am using a state_node to check whether a device has been turned on/off for a given amount of time and then send a notification to my phone. Here is an image of this:

The notification will be sent after 5 minutes and as you can see only if it was turned on but … I would like to check every other 5 min if the device remains on and the main reason is that sometimes someone at home left devices on for a long time wasting money because of power heh. Can I get some ideas for this?

Here is my current flow JSON:

[
  {
    "id": "acc66eae0bd38f04",
    "type": "tab",
    "label": "Lights On",
    "disabled": false,
    "info": "",
    "env": [

    ]
  },
  {
    "id": "53068e834c06c590",
    "type": "server-state-changed",
    "z": "acc66eae0bd38f04",
    "name": "Device is On",
    "server": "e593dd3.052432",
    "version": 4,
    "exposeToHomeAssistant": false,
    "haConfig": [
      {
        "property": "name",
        "value": ""
      },
      {
        "property": "icon",
        "value": ""
      }
    ],
    "entityidfilter": [
      "fan.living_room_switch",
      "fan.master_bedroom_switch",
      "fan.office_switch"
    ],
    "entityidfiltertype": "list",
    "outputinitially": false,
    "state_type": "str",
    "haltifstate": "on",
    "halt_if_type": "str",
    "halt_if_compare": "is",
    "outputs": 2,
    "output_only_on_state_change": true,
    "for": "5",
    "forType": "num",
    "forUnits": "minutes",
    "ignorePrevStateNull": false,
    "ignorePrevStateUnknown": false,
    "ignorePrevStateUnavailable": false,
    "ignoreCurrentStateUnknown": false,
    "ignoreCurrentStateUnavailable": false,
    "outputProperties": [
      {
        "property": "payload",
        "propertyType": "msg",
        "value": "",
        "valueType": "eventData"
      }
    ],
    "x": 130,
    "y": 100,
    "wires": [
      [
        "20ef09168211f89b"
      ],
      [

      ]
    ]
  },
  {
    "id": "20ef09168211f89b",
    "type": "template",
    "z": "acc66eae0bd38f04",
    "name": "Get Friendly Name",
    "field": "payload",
    "fieldType": "msg",
    "format": "handlebars",
    "syntax": "mustache",
    "template": "The {{payload.new_state.attributes.friendly_name}} has been ON for more than 5 minutes!!!",
    "output": "str",
    "x": 390,
    "y": 60,
    "wires": [
      [
        "7dea291ec83ed2db"
      ]
    ]
  },
  {
    "id": "7dea291ec83ed2db",
    "type": "api-call-service",
    "z": "acc66eae0bd38f04",
    "name": "Send a notification",
    "server": "e593dd3.052432",
    "version": 5,
    "debugenabled": true,
    "domain": "notify",
    "service": "mobile_app_reyniers_iphone",
    "areaId": [

    ],
    "deviceId": [

    ],
    "entityId": [

    ],
    "data": "{\"title\":\"Device is ON\",\"message\":\"{{payload}}\"}",
    "dataType": "json",
    "mergeContext": "",
    "mustacheAltTags": false,
    "outputProperties": [

    ],
    "queue": "none",
    "x": 650,
    "y": 80,
    "wires": [
      [

      ]
    ]
  },
  {
    "id": "e593dd3.052432",
    "type": "server",
    "name": "Home Assistant",
    "addon": true
  }
]

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/poll-state.html

1 Like

Yea I already discovered that one however it can only poll state for one entity at the time which leads me to something like:

Do you have a better recomendation?

Create a group for the entities you want to monitor.

An inject node into a get entities node

1 Like

@Kermit I did it as follows but is giving me all the entities and I know it because I am seeing some lights that are off being returned as on … what I am missing? :neutral_face:

[
  {
    "id": "ae1c08dc88e7af9b",
    "type": "tab",
    "label": "Flow 2",
    "disabled": false,
    "info": "",
    "env": [

    ]
  },
  {
    "id": "4ab27a7282aab7b3",
    "type": "inject",
    "z": "ae1c08dc88e7af9b",
    "name": "",
    "props": [
      {
        "p": "payload"
      }
    ],
    "repeat": "30",
    "crontab": "",
    "once": true,
    "onceDelay": "30",
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "x": 350,
    "y": 200,
    "wires": [
      [
        "03027e7b61c87a83",
        "5114071f1e286201"
      ]
    ]
  },
  {
    "id": "5114071f1e286201",
    "type": "debug",
    "z": "ae1c08dc88e7af9b",
    "name": "debug 1",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "false",
    "statusVal": "",
    "statusType": "auto",
    "x": 600,
    "y": 140,
    "wires": [

    ]
  },
  {
    "id": "03027e7b61c87a83",
    "type": "ha-get-entities",
    "z": "ae1c08dc88e7af9b",
    "name": "",
    "server": "e593dd3.052432",
    "version": 0,
    "rules": [
      {
        "property": "state",
        "logic": "is",
        "value": "on",
        "valueType": "str"
      }
    ],
    "output_type": "array",
    "output_empty_results": false,
    "output_location_type": "msg",
    "output_location": "payload",
    "output_results_count": 1,
    "x": 630,
    "y": 240,
    "wires": [
      [
        "ea41e6faa03bd5b1"
      ]
    ]
  },
  {
    "id": "ea41e6faa03bd5b1",
    "type": "debug",
    "z": "ae1c08dc88e7af9b",
    "name": "debug 2",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 840,
    "y": 200,
    "wires": [

    ]
  },
  {
    "id": "e593dd3.052432",
    "type": "server",
    "name": "Home Assistant",
    "addon": true
  }
]

Right now you’re asking for all entities whose state is on. You need to add which entities to look for.

image

1 Like