Take screenshot (service call) at a specific time each day

Hi,

need some help with my Node Red configuration. It was working fine before but I noticed for some reason I’m not getting date and time inserted in the filename.

When I test the service in Home Assistant with the code below it works fine:

{
  "filename": "/share/motioneye/Front/F-{{now().strftime('%Y-%m-%d')}}_{{now().strftime('%H-%M-%S')}}.jpg",
  "entity_id": "camera.front_door"
}

However, when I paste the code in the “Data” field of service call node in Node Red all I get is files named F-_.jpg

Thanks.

I have just found out it maybe the issue with Node Red addon ver 1.3.4 because after I restored 1.3.2 version it still works.

I am pretty sure call service node cannot render ha templates. Can you paste your flow here.

Here you go, this generates files with dates and time in my share folder (Node Red v.1.3.2):

[{"id":"8083de61.bcb","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d70b3fa6.6a8f08","type":"mqtt in","z":"8083de61.bcb","name":"Front Camera Motion!","topic":"homeassistant/binary_sensor/camera/front","qos":"0","broker":"f6099aae.0aa7f","x":160,"y":160,"wires":[["f186a94f.1fc25"]]},{"id":"42262f3a.f973f","type":"server-state-changed","z":"8083de61.bcb","name":"Front Camera Motion?","server":"d21bd910.f50568","entityidfilter":"script.frontcamdetecon","entityidfiltertype":"substring","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":160,"y":40,"wires":[["4cfeecc7.9a83ec"]]},{"id":"192d027d.6f985e","type":"mqtt out","z":"8083de61.bcb","name":"Front Camera Motion!","topic":"homeassistant/binary_sensor/camera/front","qos":"0","retain":"","broker":"f6099aae.0aa7f","x":660,"y":40,"wires":[]},{"id":"4cfeecc7.9a83ec","type":"switch","z":"8083de61.bcb","name":"Camera Motion?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":40,"wires":[["192d027d.6f985e"],["192d027d.6f985e"]]},{"id":"f186a94f.1fc25","type":"api-call-service","z":"8083de61.bcb","name":"Snapshot","server":"d21bd910.f50568","service_domain":"camera","service":"snapshot","data":"{\"entity_id\":\"camera.front_door\",\"filename\":\"/share/motioneye/Front/F-{{now().strftime('%Y-%m-%d')}}_{{now().strftime('%H-%M-%S')}}.jpg\"}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":380,"y":100,"wires":[["4932c724.3863d"]]},{"id":"4932c724.3863d","type":"debug","z":"8083de61.bcb","name":"Front","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.data.filename","x":650,"y":100,"wires":[]},{"id":"31d587f9.cdd64","type":"inject","z":"8083de61.bcb","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"x":170,"y":100,"wires":[["f186a94f.1fc25"]]},{"id":"f6099aae.0aa7f","type":"mqtt-broker","z":"","name":"MQTT","broker":"192.168.1.7","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"d21bd910.f50568","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]

Thanks.

I won’t get to test this for a few hours. Just to know are using the latest (and maintained) home assistant node (aka websocket version)?

At the moment I’m on 0.7.1 version. This one works for me at the moment. I could try to update to 0.8.0 to try but first I would need to know if I can easily revert just in case it breaks my flow.

I was unaware of any service calls that actually accepted jinja2 templates. Looks like the camera component is one. There are probably more…

https://github.com/home-assistant/home-assistant/blob/d1038ea79fa4e6d6bdbb37b2ae7ba830ab5b84d6/homeassistant/components/camera/init.py#L69

Not knowing this at the time of releasing v0.8.0 but with this knowledge now v0.8.0 would break any call-service calls trying to use a template to be processed by HA.

You could use node-red-contrib-moment to format a timestamp and use that within the call-service node to get this to work with v0.8.0.

[{"id":"b509f5e7.170168","type":"moment","z":"458f31ff.1933e","name":"","topic":"","input":"","inputType":"date","inTz":"America/Los_Angeles","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD_HH-mm-ss","locale":"en_US","output":"dateformat","outputType":"msg","outTz":"America/Los_Angeles","x":404,"y":112,"wires":[["9c0754da.956578"]]},{"id":"c1f7b89b.bb74a8","type":"mqtt in","z":"458f31ff.1933e","name":"Front Camera Motion!","topic":"homeassistant/binary_sensor/camera/front","qos":"0","broker":"8e00bea0.bcc54","x":164,"y":112,"wires":[["b509f5e7.170168"]]},{"id":"ce7f99f.a6c5868","type":"server-state-changed","z":"458f31ff.1933e","name":"Front Camera Motion?","server":"ef067c6f.620e6","entityidfilter":"script.frontcamdetecon","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on,off","halt_if_type":"str","halt_if_compare":"does_not_include","outputs":2,"output_only_on_state_change":false,"x":164,"y":48,"wires":[["35d55bf2.552394"],[]]},{"id":"35d55bf2.552394","type":"mqtt out","z":"458f31ff.1933e","name":"Front Camera Motion!","topic":"homeassistant/binary_sensor/camera/front","qos":"0","retain":"","broker":"8e00bea0.bcc54","x":404,"y":48,"wires":[]},{"id":"9c0754da.956578","type":"api-call-service","z":"458f31ff.1933e","name":"Snapshot","server":"ef067c6f.620e6","service_domain":"camera","service":"snapshot","data":"{\"entity_id\":\"camera.front_door\",\"filename\":\"/share/motioneye/Front/F-{{dateformat}}.jpg\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":604,"y":112,"wires":[["11cb8292.faac5d"]]},{"id":"11cb8292.faac5d","type":"debug","z":"458f31ff.1933e","name":"Front","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.data.filename","x":738,"y":112,"wires":[]},{"id":"7f5647e5.b65848","type":"inject","z":"458f31ff.1933e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"x":166,"y":176,"wires":[["b509f5e7.170168"]]},{"id":"8e00bea0.bcc54","type":"mqtt-broker","z":"","name":"MQTT","broker":"192.168.1.7","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

This doesn’t work in 0.7.1. I end up with files named “F-.jpg”. I will try to check if it works in 0.8.0

In v0.7.1 you would have to make sure the render templates in data is checked.

1 Like