Envois de fichier via callservice telegram_bot.send_photo

coucou,

bon je galere un peu,

j’ai une photo déposée dans le repertoire /media/
je souhaiterai l’envoyer par télégram, j’utilise un noeud call service car la palette Telegram me semble plus compliquée.

mon flow :

[{"id":"59390104.115af","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"c08b2357.f2646","type":"inject","z":"59390104.115af","name":"msg.payload = on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":150,"y":180,"wires":[["569bdb9e.fcce64"]]},{"id":"569bdb9e.fcce64","type":"api-call-service","z":"59390104.115af","name":"camera_parking","server":"a537137.2d98df","version":1,"debugenabled":true,"service_domain":"camera","service":"snapshot","entityId":"camera.camera_parking","data":"{\"filename\":\"/media/{{ entity_id.name }}_{{ now ().day }}_{{ now ().month }}_{{ now ().hour }}_{{ now ().minute }}_{{ now ().second }}.jpg\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":360,"y":180,"wires":[["370dff43.038b2","162894f0.66d94b"]]},{"id":"370dff43.038b2","type":"debug","z":"59390104.115af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":120,"wires":[]},{"id":"162894f0.66d94b","type":"change","z":"59390104.115af","name":"set msg.payload to msg.payload.photo","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.photo","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":180,"wires":[["f242967e.c92978","8d126b58.e10e58"]]},{"id":"8d126b58.e10e58","type":"debug","z":"59390104.115af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.photo","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":120,"wires":[]},{"id":"400d2db7.2f3244","type":"inject","z":"59390104.115af","name":"inject msg.payload.photo = on","props":[{"p":"payload.photo","v":"on","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":300,"wires":[["f242967e.c92978"]]},{"id":"f242967e.c92978","type":"api-call-service","z":"59390104.115af","name":"","server":"a537137.2d98df","version":1,"debugenabled":true,"service_domain":"telegram_bot","service":"send_photo","entityId":"","data":"{\"file\":\"/media/camera_jardin_30_12_0_23_23.jpg\",\"caption\":\"test\",\"target\":\"-38141xxxx\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":490,"y":300,"wires":[["12e92d42.3ab5f3"]]},{"id":"12e92d42.3ab5f3","type":"debug","z":"59390104.115af","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":380,"wires":[]},{"id":"a537137.2d98df","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}] 

Le noeud call service pour créer l’image est configuré comme :

{
    "filename": "/media/{{ entity_id.name }}_{{ now ().day }}_{{ now ().month }}_{{ now ().hour }}_{{ now ().minute }}_{{ now ().second }}.jpg"
}

Le noeud call service pour envoyer l’image sur mon groupe telegram est configuré :

{
    "file": "/media/camera_jardin_30_12_0_23_23.jpg",
    "caption": "test",
    "target": "-38141xxxx"
}

c’est ce dernier noeud que je souhaiterai personnaliser : trouver un moyen pour que chaque nouvelle image en .jpg arrivant dans ce répertoire soit envoyé et le must serait aussi qu’elle soit supprimée après l’envois.

par exemple « file »: « /media/*.jpg »

j’espere etre à peu près clair :wink:

Voilà une façon de faire… Je n’ai pas testé jusqu’au bout, je n’ai pas telegram du côté HA.
Mais le principe:

[{"id":"25bf1117.bcaaae","type":"change","z":"59390104.115af","name":"Set file","rules":[{"t":"set","p":"photo","pt":"flow","to":"'Photo_' & $fromMillis($toMillis($now()),'[M02]_[D02]_[H02]_[m02]_[s02]') & '.jpg'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":460,"wires":[["459f3fa1.c5c32"]]},{"id":"459f3fa1.c5c32","type":"api-call-service","z":"59390104.115af","name":"camera_parking","server":"d28c9492.f419c8","version":1,"debugenabled":true,"service_domain":"camera","service":"snapshot","entityId":"camera.camera_parking","data":"{\t   \"filename\": $flowContext('photo')\t}","dataType":"jsonata","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":380,"y":460,"wires":[["46dd094f.ad34e8"]]},{"id":"46dd094f.ad34e8","type":"delay","z":"59390104.115af","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":540,"y":460,"wires":[["bedefd95.69031"]]},{"id":"1b6f4bf0.0ae4a4","type":"inject","z":"59390104.115af","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":460,"wires":[["25bf1117.bcaaae"]]},{"id":"bedefd95.69031","type":"api-call-service","z":"59390104.115af","name":"Telegram","server":"d28c9492.f419c8","version":1,"debugenabled":true,"service_domain":"telegram_bot","service":"send_photo","entityId":"","data":"{\t   \"file\": $flowContext('photo'),\t   \"caption\": \"test\",\t   \"target\": \"-38141xxxx\"\t}","dataType":"jsonata","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":680,"y":460,"wires":[["57d3a70.7698058"]]},{"id":"57d3a70.7698058","type":"delay","z":"59390104.115af","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":820,"y":460,"wires":[["e6037ccb.e2cd8"]]},{"id":"7424233.07b8cdc","type":"file","z":"59390104.115af","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":1090,"y":460,"wires":[[]]},{"id":"e6037ccb.e2cd8","type":"change","z":"59390104.115af","name":"Filename","rules":[{"t":"set","p":"filename","pt":"msg","to":"photo","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":460,"wires":[["7424233.07b8cdc"]]},{"id":"d28c9492.f419c8","type":"server","name":"hassio","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

On défini le nom de la photo avec le noeud change et ensuite avec des template jsonata on créé les divers payload.

1 J'aime

salut,

bon j’ai pas mal galeré lol, j’y suis presque, il a fallu que je me vide la tete, et là je m’y remet :wink:

donc où en suis je? le débug du noeud change donne ca :

donc ca parait bien,

mais…parcequ’il y toujours un mais…

le fichier déposé reste :
image

héhé ! la colle non ? :smiley:

Je ne comprends pas ce morceau là…
Le fichier déposé ou? dans quel noeud?

Pour interpréter $flowContext, il faut que ce soit indiqué comme étant du jsonata (le signe bizarre genre intégrale). C’est fait?