Notification on HA app with image (different filenames) with NodeRed

Hello guys,

I’m trying to notify my phone when the door ring with the snap of the camera.

I made a flow, but the image sent to my phone appears to be saved on cache and it wasn’t the last that was created.

So I modified the flow, and include the File Access and File Delete nodes, to verify if the snap was created before send the notification and after that, delete the snap, but it didn’t solve my problem

Now I included a counter to change the file name of the snap, but now, the notification is coming with no images.

Can you help me?

[{"id":"da9a461e2c75968c","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"7ac03e9b868b597a","type":"api-call-service","z":"da9a461e2c75968c","name":"","server":"574882af.002ebc","version":5,"debugenabled":false,"domain":"camera","service":"snapshot","areaId":[],"deviceId":[],"entityId":["camera.rua_esq"],"data":"{\"filename\": filename}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":410,"y":180,"wires":[["b9c47819c37dbee1"]]},{"id":"3f8c38fcf378d71d","type":"api-call-service","z":"da9a461e2c75968c","name":"Notify","server":"a86c4410.e2a568","version":5,"debugenabled":true,"domain":"notify","service":"mobile_app_pedrao_iphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"title\":\"Campainha\",\t   \"message\":\"Campainha foi tocada!\",\t   \"data\":{\t       \"image\": msg.filename,\t       \"priority\":\"high\",\t       \"channel\":\"Doorbell\"\t           }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":970,"y":180,"wires":[[]]},{"id":"b9c47819c37dbee1","type":"fs-ops-access","z":"da9a461e2c75968c","name":"","path":"path","pathType":"msg","filename":"file","filenameType":"msg","read":true,"write":true,"throwerror":true,"x":630,"y":180,"wires":[["e3546535493a0c63"],["e7235d121839b19e"]]},{"id":"9af32bfbfec0fcba","type":"fs-ops-delete","z":"da9a461e2c75968c","name":"","path":"path","pathType":"msg","filename":"file","filenameType":"msg","x":1310,"y":180,"wires":[[]]},{"id":"78240ffb3a18de63","type":"delay","z":"da9a461e2c75968c","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1140,"y":180,"wires":[["9af32bfbfec0fcba"]]},{"id":"55d626dfaffdc3a4","type":"counter","z":"da9a461e2c75968c","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":280,"y":80,"wires":[["9b0c1198994540e2"]]},{"id":"9b0c1198994540e2","type":"function","z":"da9a461e2c75968c","name":"Create file name","func":"msg.path = \"/config/www/imgs/cameras/\"\nmsg.file = \"rua_esq\" + msg.count +\".jpg\"\nmsg.filename = msg.path + msg.file\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":80,"wires":[["7ac03e9b868b597a"]]},{"id":"e3546535493a0c63","type":"delay","z":"da9a461e2c75968c","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":810,"y":180,"wires":[["3f8c38fcf378d71d"]]},{"id":"e7235d121839b19e","type":"delay","z":"da9a461e2c75968c","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":620,"y":280,"wires":[["b9c47819c37dbee1"]]},{"id":"ae8811c08d782ab8","type":"inject","z":"da9a461e2c75968c","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":80,"wires":[["55d626dfaffdc3a4"]]},{"id":"574882af.002ebc","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":"a86c4410.e2a568","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}]

I just found how to solve this. The problem was on the snap’s path on Notify node.

The solution was create a new line on the function to send the correct path on the message and change the path of snap on Notify node to the path that is created before.

Captura de tela 2023-01-30 141151

2 Likes

Updating my problem.
The problem that I said about the (maybe) cache image still persists.
I attached the screenshot of the notification and you can see that the time of the snapshot is not the time of the notification (that was 9:57).


Question, maybe does the moment of automation make the snapshot, the camera image is not updated?

1 Like

Can you share the full code please :slight_smile:

My bad… I changed the flow, to try to “pre-update” the snap, and then save the snap that will be sent to the notification. But the problem persists, I really don’t know what to do.

[{"id":"da9a461e2c75968c","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"7ec873503ad50acd","type":"api-call-service","z":"da9a461e2c75968c","name":"","server":"574882af.002ebc","version":5,"debugenabled":false,"domain":"camera","service":"snapshot","areaId":[],"deviceId":[],"entityId":["camera.rua_esq"],"data":"{\"filename\": filename}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":670,"y":160,"wires":[["6f84ab8284b31416"]]},{"id":"9990c38473ca22b6","type":"inject","z":"da9a461e2c75968c","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":60,"wires":[["2d5a845bc8e48455"]]},{"id":"24dc8031da8b31bd","type":"api-call-service","z":"da9a461e2c75968c","name":"Notify","server":"a86c4410.e2a568","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pedrao_iphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"title\":\"Campainha\",\t   \"message\":\"Campainha foi tocada!\",\t   \"data\":{\t       \"image\": msg.filename_notif,\t       \"priority\":\"high\",\t       \"channel\":\"Doorbell\"\t           }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1110,"y":160,"wires":[["5f31752159fa5adf"]]},{"id":"6f84ab8284b31416","type":"fs-ops-access","z":"da9a461e2c75968c","name":"","path":"path","pathType":"msg","filename":"file","filenameType":"msg","read":true,"write":true,"throwerror":true,"x":930,"y":160,"wires":[["24dc8031da8b31bd"],["149575740c0e4ca7"]]},{"id":"149575740c0e4ca7","type":"delay","z":"da9a461e2c75968c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":920,"y":220,"wires":[["6f84ab8284b31416"]]},{"id":"3f8bcb5e30c58abb","type":"fs-ops-delete","z":"da9a461e2c75968c","name":"","path":"path","pathType":"msg","filename":"file","filenameType":"msg","x":1450,"y":140,"wires":[[]]},{"id":"5f31752159fa5adf","type":"delay","z":"da9a461e2c75968c","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1280,"y":140,"wires":[["3f8bcb5e30c58abb"]]},{"id":"67e821b4c8bbc27e","type":"counter","z":"da9a461e2c75968c","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":280,"y":160,"wires":[["6811f17a76c12dcf"]]},{"id":"6811f17a76c12dcf","type":"function","z":"da9a461e2c75968c","name":"Create file name","func":"msg.path = \"/config/www/imgs/cameras/\"\nmsg.file = \"rua_esq\" + msg.count + \".jpg\"\nmsg.filename = msg.path + msg.file\nmsg.filename_notif = \"/local/imgs/cameras/\" + msg.file\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":160,"wires":[["7ec873503ad50acd"]]},{"id":"2d5a845bc8e48455","type":"api-call-service","z":"da9a461e2c75968c","name":"","server":"574882af.002ebc","version":5,"debugenabled":false,"domain":"camera","service":"snapshot","areaId":[],"deviceId":[],"entityId":["camera.rua_esq"],"data":"{\"filename\": \"/config/www/imgs/cameras/teste.jpg\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":310,"y":60,"wires":[["93a35ab2e1a75bb0","67e821b4c8bbc27e"]]},{"id":"79f4efb822f892cd","type":"fs-ops-delete","z":"da9a461e2c75968c","name":"","path":"/config/www/imgs/cameras/","pathType":"str","filename":"teste.jpg","filenameType":"str","x":670,"y":60,"wires":[[]]},{"id":"93a35ab2e1a75bb0","type":"delay","z":"da9a461e2c75968c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":500,"y":60,"wires":[["79f4efb822f892cd"]]},{"id":"574882af.002ebc","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":"a86c4410.e2a568","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": "808b21e4896dc6c4",
        "type": "api-current-state",
        "z": "30801c09897c9fed",
        "name": "Main Door Outside Motion  ON ?",
        "server": "f22f6e73.21e16",
        "version": 3,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "binary_sensor.presence_12",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 1810,
        "y": 100,
        "wires": [
            [
                "e1309bb003cd89eb",
                "587c2d584de4b2b1"
            ],
            []
        ]
    },
    {
        "id": "587c2d584de4b2b1",
        "type": "api-call-service",
        "z": "30801c09897c9fed",
        "name": "",
        "server": "f22f6e73.21e16",
        "version": 5,
        "debugenabled": false,
        "domain": "camera",
        "service": "snapshot",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "camera.blueiris_exit_home_200"
        ],
        "data": "{\"filename\":\"/config/www/camera/exit_home_200.jpg\"}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 2220,
        "y": 140,
        "wires": [
            [
                "99db6b490c31b3bd"
            ]
        ]
    },
    {
        "id": "99db6b490c31b3bd",
        "type": "delay",
        "z": "30801c09897c9fed",
        "name": "",
        "pauseType": "delay",
        "timeout": "15",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 2460,
        "y": 140,
        "wires": [
            [
                "c4e4ca9b25594e2b"
            ]
        ]
    },
    {
        "id": "c4e4ca9b25594e2b",
        "type": "api-call-service",
        "z": "30801c09897c9fed",
        "name": "",
        "server": "",
        "version": 5,
        "debugenabled": false,
        "domain": "telegram_bot",
        "service": "send_photo",
        "areaId": [],
        "deviceId": [],
        "entityId": [],
        "data": "{\"file\":\"/config/www/camera/exit_home_200.jpg\"}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 2690,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "4876a30cd660d6de",
        "type": "api-current-state",
        "z": "30801c09897c9fed",
        "name": "sensor.someone_home ?",
        "server": "f22f6e73.21e16",
        "version": 3,
        "outputs": 2,
        "halt_if": "True",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "sensor.someone_home",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "x": 1530,
        "y": 100,
        "wires": [
            [],
            [
                "808b21e4896dc6c4"
            ]
        ]
    },
    {
        "id": "e1309bb003cd89eb",
        "type": "api-call-service",
        "z": "30801c09897c9fed",
        "name": "",
        "server": "f22f6e73.21e16",
        "version": 5,
        "debugenabled": false,
        "domain": "camera",
        "service": "record",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "camera.blueiris_exit_home_200"
        ],
        "data": "{\"filename\":\"/config/www/camera/blueiris_exit_home_200.mp4\"}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 2250,
        "y": 200,
        "wires": [
            [
                "37a2ccecbdcc0b07"
            ]
        ]
    },
    {
        "id": "37a2ccecbdcc0b07",
        "type": "delay",
        "z": "30801c09897c9fed",
        "name": "",
        "pauseType": "delay",
        "timeout": "40",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 2460,
        "y": 200,
        "wires": [
            [
                "3ee55774aab9cd1f"
            ]
        ]
    },
    {
        "id": "3ee55774aab9cd1f",
        "type": "api-call-service",
        "z": "30801c09897c9fed",
        "name": "",
        "server": "",
        "version": 5,
        "debugenabled": false,
        "domain": "telegram_bot",
        "service": "send_video",
        "areaId": [],
        "deviceId": [],
        "entityId": [],
        "data": "{\"file\":\"/config/www/camera/blueiris_exit_home_200.mp4\"}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 2710,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "492c803a84d6694a",
        "type": "server-state-changed",
        "z": "30801c09897c9fed",
        "name": "Home Is Away ?",
        "server": "f22f6e73.21e16",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.house_away",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "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": 1240,
        "y": 100,
        "wires": [
            [
                "4876a30cd660d6de"
            ],
            []
        ]
    },
    {
        "id": "f22f6e73.21e16",
        "type": "server",
        "name": "yuval_Home Assistant",
        "version": 4,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
 
    }
]

can you try it

This flow is to send the snap to telegram, so I will need to configure a bot to make it work. I will try and let you know when I do it… Thanks!

I just analyze the snaps created, and I saw when the snaps were created, the image of the camera is not updates, so that’s why it is sending a “wrong” and past snap.
In the image below, you can see that snap was created at 15:07 and camera hour is 12:04.
Does anyone know how can I force an update?
PS: I use RTSPtoWeb - WebRTC for my cameras.
Captura de tela 2023-02-08 210012