Node suggestion for attribute change

I need some help converting the following automation to NodeRED since I am stuck:

alias: Download Ring Video (Front Porch)
trigger:
  - platform: state
    entity_id: binary_sensor.front_porch_motion
    to: 'on'
action:
  - wait_for_trigger:
      - platform: state
        entity_id: select.front_porch_event_select
        attribute: eventId
    timeout: '00:05'
  - service: downloader.download_file
    data_template:
      url: '{{ states.select.front_porch_event_select.attributes.recordingUrl }}'
      subdir: front_porch
      filename: '{{ now().strftime( ''%Y%m%dT%H%M%S_motion.mp4'' ) }}'
      overwrite: false

For the first binary_sensor.front_porch_motion I am using a trigger:state node, not sure if it is the right one though. Now, my problem comes with select.front_porch_event_select. For that one, I am using a wait until (see below) node but I don’t know what to use in the is condition since the automation says nothing but:

This automation is initially triggered any time a motion event starts. Once triggered, it waits for the eventId attribute to change, which indicates that the recording of the new event is ready.

what value can I use there? All I can see in the Developer Tools is Motion 1 but it never changes to anything else so I am not sure what could I use there

Ok, I will answer myself and help others in case they find the same issue. Here is the entire flow:

and this is the code for it:

[
    {
        "id": "3ebcf253d4f27a57",
        "type": "tab",
        "label": "DownloadRingVideos",
        "disabled": false,
        "info": "Downloading recorded videos using the Event Stream",
        "env": []
    },
    {
        "id": "9f7c0ff7f44a56e7",
        "type": "trigger-state",
        "z": "3ebcf253d4f27a57",
        "name": "",
        "server": "e593dd3.052432",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityid": "binary_sensor.front_door_motion",
        "entityidfiltertype": "exact",
        "debugenabled": true,
        "constraints": [
            {
                "targetType": "this_entity",
                "targetValue": "",
                "propertyType": "current_state",
                "propertyValue": "new_state.state",
                "comparatorType": "is",
                "comparatorValueDatatype": "str",
                "comparatorValue": "on"
            }
        ],
        "inputs": 1,
        "outputs": 2,
        "customoutputs": [],
        "outputinitially": false,
        "state_type": "str",
        "enableInput": true,
        "x": 210,
        "y": 340,
        "wires": [
            [
                "a2f347e00498f687"
            ],
            []
        ]
    },
    {
        "id": "a2f347e00498f687",
        "type": "ha-wait-until",
        "z": "3ebcf253d4f27a57",
        "name": "",
        "server": "e593dd3.052432",
        "version": 2,
        "outputs": 2,
        "entityId": "select.front_door_event_select",
        "entityIdFilterType": "exact",
        "property": "attributes.eventId",
        "comparator": "is_not",
        "value": "Motion 1",
        "valueType": "str",
        "timeout": "5",
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "outputProperties": [],
        "entityLocation": "data",
        "entityLocationType": "none",
        "x": 480,
        "y": 300,
        "wires": [
            [
                "79bdac2c7f11dc9c"
            ],
            []
        ]
    },
    {
        "id": "db10e81e4a1d16e1",
        "type": "api-call-service",
        "z": "3ebcf253d4f27a57",
        "name": "",
        "server": "e593dd3.052432",
        "version": 5,
        "debugenabled": true,
        "domain": "downloader",
        "service": "download_file",
        "areaId": [],
        "deviceId": [],
        "entityId": [],
        "data": "{\t   \"url\": msg.url,\t   \"subdir\": msg.subdir,\t   \"filename\": msg.filename,\t   \"overwrite\": false\t}",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1110,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "7b3ca39905992163",
        "type": "function",
        "z": "3ebcf253d4f27a57",
        "name": "BuildPayload",
        "func": "let front_camera = global.get('homeassistant').homeAssistant.states[\"camera.front_door\"];\nlet current_date = msg.payload;\n\nlet dateAsArray = current_date.split(\".\", 3);\n\nlet month_year = dateAsArray[0] + \"-\" + dateAsArray[2];\nlet friendly_name = front_camera.attributes.friendly_name;\n\nreturn {\n    \"url\": front_camera.attributes.video_url,\n    \"subdir\": friendly_name.replace(/\\s+/g, '_').toLowerCase() + \"/\" + month_year,\n    \"filename\": current_date + \".mp4\"\n};",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 890,
        "y": 280,
        "wires": [
            [
                "db10e81e4a1d16e1"
            ]
        ]
    },
    {
        "id": "79bdac2c7f11dc9c",
        "type": "moment",
        "z": "3ebcf253d4f27a57",
        "name": "",
        "topic": "",
        "input": "",
        "inputType": "date",
        "inTz": "America/New_York",
        "adjAmount": 0,
        "adjType": "days",
        "adjDir": "add",
        "format": "MM.DD.YYYY.HH.mm.ss",
        "locale": "C",
        "output": "",
        "outputType": "msg",
        "outTz": "America/New_York",
        "x": 680,
        "y": 280,
        "wires": [
            [
                "7b3ca39905992163"
            ]
        ]
    },
    {
        "id": "e593dd3.052432",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

In the end, I finish setting the value to not be Motion 1 which works, at least for now, :man_shrugging: these are the key lines:

"property": "attributes.eventId",
"comparator": "is_not",
"value": "Motion 1",

Below is flow that I’m using and works. Note that the delay’s are important as it take time for Ring to process the image.

[{"id":"f9beaa6b.4ea1b8","type":"server-state-changed","z":"b7ad727.de6df9","name":"Ring Front Door Motion","server":"8a3231e1.3f0e1","version":4,"exposeToHomeAssistant":true,"haConfig":[{"property":"name","value":"Enable/Disable Door Presence"},{"property":"icon","value":"mdi:motion"}],"entityidfilter":"binary_sensor.front_door_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"$entity().state = \"on\" and (\t   $entities(\"sensor.iphoneexpress_zone\").state = \"home\" or $entities(\"sensor.garbineiphone_zone\").state = \"home\"\t)","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":180.83341217041016,"y":1367.2618780136108,"wires":[["ac5e3332.800d3","12265986.288096","ce9b1a2d.234938","b3278df5.65fcb"],[]]},{"id":"ac5e3332.800d3","type":"time-range-switch","z":"b7ad727.de6df9","name":"After 10:45pm & before 5:43am","lat":"33.2011989","lon":"-96.9083990","startTime":"22:45","endTime":"05:43","startOffset":0,"endOffset":0,"x":457.08341217041016,"y":1367.2619009017944,"wires":[["ed69d919.b670a8"],[]]},{"id":"a2202991.897c28","type":"comment","z":"b7ad727.de6df9","name":"Ring Front Door motion detection","info":"","x":209.58341217041016,"y":1316.0118761062622,"wires":[]},{"id":"ed69d919.b670a8","type":"switch","z":"b7ad727.de6df9","name":"Set ON/OFF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":698.3334197998047,"y":1361.0118780136108,"wires":[["a79972c4.ad8ad","33ae4bbf.cb18c4"],[]]},{"id":"a79972c4.ad8ad","type":"api-call-service","z":"b7ad727.de6df9","name":"Turn Entrance & Garage lamp ON","server":"8a3231e1.3f0e1","version":5,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.entrance_porch_light","switch.garage_porch_light"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":993.3334274291992,"y":1336.0118761062622,"wires":[[]]},{"id":"3b1e531a.09175c","type":"api-call-service","z":"b7ad727.de6df9","name":"Turn Entrance & Garage lamp OFF","server":"8a3231e1.3f0e1","version":5,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.entrance_porch_light","switch.garage_porch_light"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":989.5834274291992,"y":1439.7618780136108,"wires":[[]]},{"id":"33ae4bbf.cb18c4","type":"delay","z":"b7ad727.de6df9","name":"3 minute delay","pauseType":"delay","timeout":"3","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":907.0834274291992,"y":1388.5118780136108,"wires":[["3b1e531a.09175c"]]},{"id":"9dd2cee1.6eac6","type":"api-call-service","z":"b7ad727.de6df9","name":"Save Ring image","server":"8a3231e1.3f0e1","version":5,"debugenabled":false,"domain":"downloader","service":"download_file","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":1040.1190795898438,"y":1546.7261695861816,"wires":[["c4d724f6.3c47b8"]]},{"id":"ee4f2850.98b888","type":"comment","z":"b7ad727.de6df9","name":"Ring Front Door download image","info":"","x":485.8333511352539,"y":1477.083291053772,"wires":[]},{"id":"ce9b1a2d.234938","type":"delay","z":"b7ad727.de6df9","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":420.83335876464844,"y":1548.3332920074463,"wires":[["b2ea08fdd00e856b"]]},{"id":"b3278df5.65fcb","type":"debug","z":"b7ad727.de6df9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":437.1428680419922,"y":1309.523772239685,"wires":[]},{"id":"b2ea08fdd00e856b","type":"api-render-template","z":"b7ad727.de6df9","name":"Downloader Template","server":"8a3231e1.3f0e1","version":0,"template":"    {\n      \"data\":\n          {\n            \"subdir\": \"downloads\",\n            \"url\": \"{{ state_attr(\"camera.front_door\", \"video_url\") }}\",\n            \"filename\": \"Ring-FD-{{now().year}}-{{now().month}}.{{now().day}}.mp4\",\n            \"overwrite\": true\n          }\n    }\n","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"","templateLocationType":"none","x":634.2857055664062,"y":1547.142900466919,"wires":[["f6fc10e0290fe04a"]]},{"id":"f6fc10e0290fe04a","type":"json","z":"b7ad727.de6df9","name":"","property":"payload","action":"","pretty":false,"x":851.4286193847656,"y":1547.1428995132446,"wires":[["9dd2cee1.6eac6"]]},{"id":"8a3231e1.3f0e1","type":"server","name":"Hassio","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"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}]
1 Like

wanted to try your solution but is not allowing me to import it since it seems to have an error:

also, could you format all the code and put it within the code tags? it will be easier to read.

Note: I think the editor messed up with the JSON

Any ideas on why my flow is triggered three times? I get three videos, three notifications, and so on … and the video is the same :expressionless:

Apologies, not sure what I was thinking. Let me know if you need additional assistance.

1 Like