How to use If state change

Sorry but im really new at this, i was looking for a nodered thing state monitoring solution.
My problem is:
Monitor the power of a outlet, and when change from above 5W to 1W for more than 1 minute drop a google tts message to say about landry is done.

i have this by now, but i dont know how to add the “for 1 minute”

or the best solution is going automation on HA menus?

Use a wait-until node checking if the state is greater than 1 with a timeout of 1 minute. Use the timeout output, the bottom one, to connect to the call-service node.

please can you give me a better example, i know some of what you talking about, but im really new at this still learning a lot

is for a washer monitor satus, this would not trigger everytime the washer is in 0 resting?

After the trigger state node triggers the wait until node is activated. Which will start watching the power and if it goes above 1 it will send output to the top, does nothing the flow stops. If it doesn’t go above 1 for a minute it will output to the bottom, the timeout output,

[{"id":"2348577a73a43fc3","type":"trigger-state","z":"c89d915bdff0f798","name":"","server":"","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.washer","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":">=","comparatorValueDatatype":"num","comparatorValue":"2"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"<=","comparatorValueDatatype":"num","comparatorValue":"1"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":216,"y":896,"wires":[["e6d7935ca1a550ad"],[]]},{"id":"e6d7935ca1a550ad","type":"ha-wait-until","z":"c89d915bdff0f798","name":"","server":"","version":2,"outputs":2,"entityId":"sensor.washer","entityIdFilterType":"exact","property":"state","comparator":"gt","value":"1","valueType":"num","timeout":"1","timeoutType":"num","timeoutUnits":"minutes","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":428,"y":896,"wires":[[],["4862a04afb3d4121"]]},{"id":"4862a04afb3d4121","type":"debug","z":"c89d915bdff0f798","name":"send notification","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":648,"y":896,"wires":[]}]
1 Like

sorry to ask, but how you pass the code you write to nodered? :slight_smile:

https://nodered.org/docs/user-guide/editor/workspace/import-export

1 Like


i end up double checking, i dont know why every hour keep sending the tts

i dont know why the plug give sometimes 2W without doing nothing, this activate the 1st trigger

could you please share the ccode? not just a picture?

This is one way, set the appropiate entity.

If washing goes above 5w, then the trigger node is enabled. When power drops down for a minute, it notifies you and turns off the trigger node, so it won’t notify you any further until power goes above 5w.

[{"id":"dcca51c4c317841f","type":"trigger-state","z":"b3e0d080.4aac7","name":"washing machine","server":"9405c3fe.d0a6c","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.c2c_triangulos","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"inputs":1,"outputs":4,"customoutputs":[{"messageType":"payload","messageValue":"start","messageValueType":"str","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"<=","comparatorValue":"1","comparatorValueDataType":"num"},{"messageType":"payload","messageValue":"stop","messageValueType":"str","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":">","comparatorValue":"1","comparatorValueDataType":"num"}],"outputinitially":false,"state_type":"num","enableInput":true,"x":4360,"y":180,"wires":[[],[],["8d2fcd8e5d762d20"],["8d2fcd8e5d762d20"]]},{"id":"ec6658a1ff0cc10d","type":"change","z":"b3e0d080.4aac7","name":"enable","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":4210,"y":160,"wires":[["dcca51c4c317841f"]]},{"id":"e2b43e97faba80c4","type":"change","z":"b3e0d080.4aac7","name":"disable","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":4200,"y":200,"wires":[["dcca51c4c317841f"]]},{"id":"8d2fcd8e5d762d20","type":"trigger","z":"b3e0d080.4aac7","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":4570,"y":240,"wires":[["e2b43e97faba80c4","a3aa4165acd06b29"]]},{"id":"a3aa4165acd06b29","type":"api-call-service","z":"b3e0d080.4aac7","name":"notify","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":4750,"y":240,"wires":[[]]},{"id":"ebe09439874c5ded","type":"server-state-changed","z":"b3e0d080.4aac7","name":"washing machine","server":"9405c3fe.d0a6c","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.c2c_triangulos","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"5","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[],"x":4040,"y":160,"wires":[["ec6658a1ff0cc10d"],[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
[
    {
        "id": "82e1d6816c2271e5",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fc45ee117404f0cd",
        "type": "trigger-state",
        "z": "82e1d6816c2271e5",
        "name": "Lavadora",
        "server": "5989b2abe6832582",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityid": "sensor.lavadora_energy_power",
        "entityidfiltertype": "exact",
        "debugenabled": false,
        "constraints": [
            {
                "targetType": "this_entity",
                "targetValue": "",
                "propertyType": "previous_state",
                "propertyValue": "old_state.state",
                "comparatorType": ">=",
                "comparatorValueDatatype": "num",
                "comparatorValue": "2"
            },
            {
                "targetType": "this_entity",
                "targetValue": "",
                "propertyType": "current_state",
                "propertyValue": "new_state.state",
                "comparatorType": "<=",
                "comparatorValueDatatype": "num",
                "comparatorValue": "1"
            }
        ],
        "inputs": 0,
        "outputs": 2,
        "customoutputs": [],
        "outputinitially": false,
        "state_type": "str",
        "enableInput": false,
        "x": 100,
        "y": 60,
        "wires": [
            [
                "3a1635725f659bfa"
            ],
            []
        ]
    },
    {
        "id": "a7e5ef4bc9d21d77",
        "type": "api-call-service",
        "z": "82e1d6816c2271e5",
        "name": "anuncio",
        "server": "5989b2abe6832582",
        "version": 5,
        "debugenabled": false,
        "domain": "tts",
        "service": "google_translate_say",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "media_player.cuarto"
        ],
        "data": "{\"message\":\"Se acabó el ciclo de lavado, por favor atender\",\"language\":\"es\"}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 640,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "3a1635725f659bfa",
        "type": "delay",
        "z": "82e1d6816c2271e5",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "minutes",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 260,
        "y": 60,
        "wires": [
            [
                "58bcef0202725ab1"
            ]
        ]
    },
    {
        "id": "58bcef0202725ab1",
        "type": "api-current-state",
        "z": "82e1d6816c2271e5",
        "name": "check if power is 0",
        "server": "5989b2abe6832582",
        "version": 3,
        "outputs": 2,
        "halt_if": "0",
        "halt_if_type": "num",
        "halt_if_compare": "is",
        "entity_id": "sensor.lavadora_energy_power",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [],
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 450,
        "y": 60,
        "wires": [
            [
                "a7e5ef4bc9d21d77"
            ],
            []
        ]
    },
    {
        "id": "5989b2abe6832582",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": "at: ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "h23",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": true
    }
]

It’s just copy paste now:

[{"id":"6368ad8b5d8248b1","type":"api-call-service","z":"82e1d6816c2271e5","name":"anuncio","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"tts","service":"google_translate_say","areaId":[],"deviceId":[],"entityId":["media_player.cuarto"],"data":"{\"message\":\"Se acabó el ciclo de lavado, por favor atender\",\"language\":\"es\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1020,"y":560,"wires":[[]]},{"id":"6f2a6ccecec140e1","type":"trigger-state","z":"82e1d6816c2271e5","name":"sensor.lavadora_energy_power","server":"9405c3fe.d0a6c","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.lavadora_energy_power","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"inputs":1,"outputs":4,"customoutputs":[{"messageType":"payload","messageValue":"start","messageValueType":"str","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"<=","comparatorValue":"1","comparatorValueDataType":"num"},{"messageType":"payload","messageValue":"stop","messageValueType":"str","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":">","comparatorValue":"1","comparatorValueDataType":"num"}],"outputinitially":false,"state_type":"num","enableInput":true,"x":570,"y":500,"wires":[[],[],["bec6bd18bbfb7876"],["bec6bd18bbfb7876"]]},{"id":"7f4d4e95443d2cdd","type":"change","z":"82e1d6816c2271e5","name":"enable","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":480,"wires":[["6f2a6ccecec140e1"]]},{"id":"9d3022711b3f8791","type":"change","z":"82e1d6816c2271e5","name":"disable","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":520,"wires":[["6f2a6ccecec140e1"]]},{"id":"bec6bd18bbfb7876","type":"trigger","z":"82e1d6816c2271e5","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":830,"y":560,"wires":[["9d3022711b3f8791","6368ad8b5d8248b1"]]},{"id":"c5ce306b870eb88b","type":"server-state-changed","z":"82e1d6816c2271e5","name":"sensor.lavadora_energy_power","server":"9405c3fe.d0a6c","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.lavadora_energy_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"5","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[],"x":170,"y":480,"wires":[["7f4d4e95443d2cdd"],[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

@zeroskrull
here is my washing / dryer machine flow hope it helps you
you need power-monitor node

what it does:
Send notification when washing machine starts (and goes above 100W)

Send notification when washing machine is finished. And calculate time and cost of this cycle.
Send all information into a telegram message

After 5 minutes below 3W shuts down the wall plug

[{"id":"b192e4f85789eed1","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"488f6ca5ab7bfdb4","type":"switch","z":"b192e4f85789eed1","name":"event stop","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":180,"wires":[["d5c31e4a0011a36f"]]},{"id":"0e60040adf175db9","type":"power-monitor","z":"b192e4f85789eed1","name":"Wasmachine","startthreshold":"100","stopthreshold":"0","startafter":"1","stopafter":"1","x":330,"y":180,"wires":[["488f6ca5ab7bfdb4","554e0e90cc6fa65f"]]},{"id":"d5c31e4a0011a36f","type":"function","z":"b192e4f85789eed1","name":"","func":"msg.payload.time = Math.round(msg.payload.time / 60);\nmsg.payload.cost = (msg.payload.energy * global.get('homeassistant.homeAssistant.states')['input_number.energy_static_price'].state).toFixed(2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":180,"wires":[["cf3c70fabec6a862"]]},{"id":"cf3c70fabec6a862","type":"template","z":"b192e4f85789eed1","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"De {{ payload.name }} is klaar 🛑\n⏲️ Totale tijd: {{ payload.time }} min.\n⚡ Totaal vebruik : {{ payload.energy }} kWh\n💸 Kosten wasbeurt: € {{ payload.cost }}","output":"str","x":880,"y":180,"wires":[["8b524aadfdde527d"]]},{"id":"8fe02fb89119e2f7","type":"server-state-changed","z":"b192e4f85789eed1","name":"Wasmachine","server":"85cb4144.a30f7","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.wasmachine_electric_consumption_w","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":130,"y":180,"wires":[["0e60040adf175db9","7974e71ea1030da3"]]},{"id":"8b524aadfdde527d","type":"function","z":"b192e4f85789eed1","name":"","func":"msg.payload =\n{\n    chatId: 'xxxxxxxx',\n    type: 'message',\n    content: msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":180,"wires":[["7ae1d5a2b620e7fb"]]},{"id":"554e0e90cc6fa65f","type":"switch","z":"b192e4f85789eed1","name":"start","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":140,"wires":[["a37c01bc0c02f921"]]},{"id":"a37c01bc0c02f921","type":"function","z":"b192e4f85789eed1","name":"","func":"msg.payload = {\n    \"chatId\": \"xxxxxxxx\", \n    \"type\":\"message\", \n    \"content\":\n    \"Wasmachine is AAN 🟢\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":140,"wires":[["7ae1d5a2b620e7fb"]]},{"id":"9e1935c24f78c795","type":"api-call-service","z":"b192e4f85789eed1","name":"Wasmachine Off","server":"85cb4144.a30f7","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.wasmachine"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":260,"wires":[[]]},{"id":"7974e71ea1030da3","type":"switch","z":"b192e4f85789eed1","name":"< of > 3W ?","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"3","vt":"num"},{"t":"gte","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":260,"wires":[["83c37d444830a84c"],["3727e2334f355138"]],"outputLabels":["Si","No"]},{"id":"83c37d444830a84c","type":"trigger","z":"b192e4f85789eed1","name":"","op1":"","op2":"Off","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"min","reset":"On","bytopic":"all","topic":"topic","outputs":1,"x":530,"y":260,"wires":[["9e1935c24f78c795"]]},{"id":"3727e2334f355138","type":"change","z":"b192e4f85789eed1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":320,"wires":[["83c37d444830a84c"]]},{"id":"3a38162619f26fcf","type":"comment","z":"b192e4f85789eed1","name":"Wasmachine Power Monitor en auto Off","info":"","x":195,"y":100,"wires":[]},{"id":"7ae1d5a2b620e7fb","type":"telegram sender","z":"b192e4f85789eed1","name":"","bot":"","haserroroutput":false,"outputs":1,"x":1270,"y":160,"wires":[[]]},{"id":"85cb4144.a30f7","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]