Check if scene is available

Hi everyone,

I recently change one of my Node RED flows that triggers when a harmony activity starts.
It then creates a new scene with the create scene service of a few lights and turns them all off right after. When the Harmony activity ends, I activate the scene so all lights switch to their old “on” state.

[{"id":"ea2c0f58.23bbe","type":"tab","label":"Kino Harmony","disabled":false,"info":""},{"id":"1a49af3d.5f8581","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Beamer command off","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.harmony_hub","data":"{\"device\":60946313,\"command\":\"PowerOff\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":400,"y":300,"wires":[["19762dd3.0e74d2"]]},{"id":"19762dd3.0e74d2","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Beamer command off","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.harmony_hub","data":"{\"device\":60946313,\"command\":\"PowerOff\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":620,"y":300,"wires":[[]]},{"id":"927a4922.f91a58","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Light Rack off","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.rack","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":80,"wires":[[]]},{"id":"1fcf032a.6675ed","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Light Esszimmer off","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.esszimmer","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":550,"y":120,"wires":[[]]},{"id":"c68f104.af92af","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Light Sofalampe off","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.sofalampe","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":550,"y":160,"wires":[[]]},{"id":"728d44c2.e2f12c","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Light Leinwand off","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.leinwand","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":550,"y":200,"wires":[[]]},{"id":"e2b28b38.cb5098","type":"server-state-changed","z":"ea2c0f58.23bbe","name":"Kino On/Off","server":"929b5bd7.3a2728","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.kino","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":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":110,"y":220,"wires":[["2ac0e308.111fec"],["1a49af3d.5f8581","5de45ce0.8040f4","cf7e6359.1045f"]]},{"id":"282d9f70.fc03b","type":"comment","z":"ea2c0f58.23bbe","name":"Kino Harmony Activity","info":"","x":140,"y":40,"wires":[]},{"id":"2ac0e308.111fec","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Snapshot Wohnzimmer","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"scene","service":"create","entityId":"","data":"{\"scene_id\":\"wohnzimmer_lichter\",\"snapshot_entities\":\"light.rack,light.sofalampe,light.leinwand\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":290,"y":100,"wires":[["cfebb4f.90ab548"]]},{"id":"cfebb4f.90ab548","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Snapshot Esszimmer","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"scene","service":"create","entityId":"","data":"{\"scene_id\":\"esszimmer_lichter\",\"snapshot_entities\":\"light.esszimmer\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":300,"y":140,"wires":[["3ef5ec32.5858d4"]]},{"id":"3ef5ec32.5858d4","type":"delay","z":"ea2c0f58.23bbe","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":300,"y":180,"wires":[["927a4922.f91a58","1fcf032a.6675ed","c68f104.af92af","728d44c2.e2f12c"]]},{"id":"5de45ce0.8040f4","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Restore Wohnzimmer","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"","data":"{\"entity_id\":\"scene.wohnzimmer_lichter\",\"transition\":4}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":400,"y":360,"wires":[[]]},{"id":"cf7e6359.1045f","type":"api-call-service","z":"ea2c0f58.23bbe","name":"Restore Esszimmer","server":"929b5bd7.3a2728","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"","data":"{\"entity_id\":\"scene.esszimmer_lichter\",\"transition\":6}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":390,"y":420,"wires":[[]]},{"id":"929b5bd7.3a2728","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

The problem is, if I restart my Home Assistant instance in the meantime the scene will be deleted (standard behaviour) and no light will be turned on.

So what I want to do know is to implement a check if a scene with a specific name is created or not.

How could I do this?

Thanks in advance!

Regards
Stefan

Check if the entity id exists using a function node or the get-entities node.

How would I do this? I tried it with the attributes.friendly_name in the get-entities node as described here Check if entity exists. Unfortunately I always get no result. Doesn´t matter if the scene exists or not. What am I doing wrong here? Sorry for asking, never worked with the get-entities node or function node before.

[{"id":"a714c81c.7547d8","type":"inject","z":"ea2c0f58.23bbe","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":284,"y":496,"wires":[["6db501c1.41c84"]]},{"id":"2af63188.5b277e","type":"debug","z":"ea2c0f58.23bbe","name":"scene doesn't exist","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":826,"y":480,"wires":[]},{"id":"6db501c1.41c84","type":"ha-get-entities","z":"ea2c0f58.23bbe","name":"","rules":[{"property":"entity_id","logic":"is","value":"scene.wohnzimmer_lichter","valueType":"str"}],"output_type":"count","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":454,"y":496,"wires":[["2301bcc9.625ca4"]]},{"id":"2301bcc9.625ca4","type":"switch","z":"ea2c0f58.23bbe","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":496,"wires":[["2af63188.5b277e"],["314cab00.bf1496"]]},{"id":"314cab00.bf1496","type":"debug","z":"ea2c0f58.23bbe","name":"scene does exist","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":826,"y":512,"wires":[]}]

image

[{"id":"a7690ae6.1bf148","type":"inject","z":"ea2c0f58.23bbe","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":720,"wires":[["3236f95.e314f06"]]},{"id":"3236f95.e314f06","type":"function","z":"ea2c0f58.23bbe","name":"","func":"const states = global.get(\"homeassistant\").homeAssistant.states;\n\nif(states[\"scene.wohnzimmer_lichter\"]) {\n    return [null, msg];\n}\n\nreturn [msg, null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":348,"y":720,"wires":[["d8bc0fd2.26126"],["bf014e53.69da7"]]},{"id":"d8bc0fd2.26126","type":"debug","z":"ea2c0f58.23bbe","name":"scene doesn't exist","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":554,"y":704,"wires":[]},{"id":"bf014e53.69da7","type":"debug","z":"ea2c0f58.23bbe","name":"scene does exist","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":554,"y":736,"wires":[]}]
1 Like

Oh, sometimes you just don´t see the easy things. Didn´t knew I could just search for entity_id in the get entities node. Is it better to do with the get entities node or the fuction node? The get entities is the one I understand better but is it maybe better to use the fuctions node due to something I don´t know about yet?
Thank you so much already for your help.

No real difference I would use the one you understand the best so in the future, you can still understand what you had done.

1 Like