I’ve put buttons on peoples’ bedside cabinets in our house. These are used to change brightness of the respective bedside lamp or send a broadcast message that someone needs help. I don’t want to to duplicate the same flow/automation for every button.
Currently I’m doing this by extracting a part of the button’s entity name and using that for either the broadcast message or to form part of the entity id of the light that needs to have brightness changed.
Current flow is below (which works BTW), but this is my first time doing this and I’m wondering if there’s a better way? There can be two buttons in the same room (either side of a bed).
[{"id":"6834cbba8bef9da4","type":"tab","label":"mqtt events","disabled":false,"info":"","env":[]},{"id":"fc972fa08541584c","type":"switch","z":"6834cbba8bef9da4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"hold","vt":"str"},{"t":"eq","v":"double","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":550,"y":100,"wires":[["67dcdba3237ad47e"],["d50923f54f8c5aaa"],["1309d4dfd440f42f"]]},{"id":"d092135f570ea7b3","type":"api-call-service","z":"6834cbba8bef9da4","name":"Announce call","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"tts","service":"google_translate_say","areaId":[],"deviceId":[],"entityId":["media_player.all_speakers"],"data":"{\"message\":\"Please contact \" & msg.topic & \" to see what they need\",\"language\":\"en\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":980,"y":200,"wires":[["3f773173c0ac7d3c"]]},{"id":"3f773173c0ac7d3c","type":"api-call-service","z":"6834cbba8bef9da4","name":"Notify Phone","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_steves_iphone_13","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"Call \"& msg.topic &\" to see what they want please!\",\"title\":\"The House\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1170,"y":200,"wires":[[]]},{"id":"d50923f54f8c5aaa","type":"api-call-service","z":"6834cbba8bef9da4","name":"","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"automation","service":"trigger","areaId":[],"deviceId":[],"entityId":["automation.steve_bedside_all_lights_off"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":770,"y":140,"wires":[[]]},{"id":"37fb642d504fb536","type":"mqtt in","z":"6834cbba8bef9da4","name":"Receive Button Payload","topic":"zigbee2mqtt/+/action","qos":"2","datatype":"auto-detect","broker":"55860a44a1511913","nl":false,"rap":true,"rh":0,"inputs":0,"x":120,"y":40,"wires":[["05efa74fcae4b56f"]]},{"id":"1309d4dfd440f42f","type":"api-call-service","z":"6834cbba8bef9da4","name":"Set Volumes to 25%","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.all_speakers"],"data":"{\"volume_level\":\"0.25\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":760,"y":200,"wires":[["d092135f570ea7b3"]]},{"id":"05efa74fcae4b56f","type":"function","z":"6834cbba8bef9da4","name":"if bedside, get name","func":"var bedside = msg.topic.toLowerCase().includes('bedside')\nif(bedside==true) {\n var caller = msg.topic.split('/');\n caller = caller[1].split('_');\n msg.topic = caller[0];\n return msg;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":100,"wires":[["fc972fa08541584c"]]},{"id":"67dcdba3237ad47e","type":"function","z":"6834cbba8bef9da4","name":"Make lamp name","func":"// light.master_steve_bedside_lamp\n\nvar start = \"light.\";\nvar finish = \"_bedside_lamp\";\nmsg.entity_id = start.concat(msg.topic, finish);\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":100,"wires":[["bcf0fa1ac910c49f"]]},{"id":"bcf0fa1ac910c49f","type":"api-current-state","z":"6834cbba8bef9da4","name":"Get Light Brightness","server":"e6b2fc324dca9de0","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{ entity_id }}","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","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":980,"y":100,"wires":[["dfc197454bb67f95"]]},{"id":"dfc197454bb67f95","type":"switch","z":"6834cbba8bef9da4","name":"","property":"data.attributes.brightness","propertyType":"msg","rules":[{"t":"null"},{"t":"btwn","v":"1","vt":"num","v2":"85","v2t":"num"},{"t":"btwn","v":"86","vt":"num","v2":"170","v2t":"num"},{"t":"btwn","v":"171","vt":"num","v2":"255","v2t":"num"}],"checkall":"true","repair":false,"outputs":4,"x":1170,"y":100,"wires":[["2eeb0a2b16d4159a"],["d81a29dd6f9f5aa7"],["b05a4ceeb9603738"],["0a8f476b131f55b1"]]},{"id":"2eeb0a2b16d4159a","type":"api-call-service","z":"6834cbba8bef9da4","name":"Is Null","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{ entity_id }}"],"data":"{\"brightness\":85}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1350,"y":80,"wires":[[]]},{"id":"d81a29dd6f9f5aa7","type":"api-call-service","z":"6834cbba8bef9da4","name":"Is Low","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{ entity_id }}"],"data":"{\"brightness\":170}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1350,"y":120,"wires":[[]]},{"id":"b05a4ceeb9603738","type":"api-call-service","z":"6834cbba8bef9da4","name":"Is Med","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{ entity_id }}"],"data":"{\"brightness\":254}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1350,"y":160,"wires":[[]]},{"id":"0a8f476b131f55b1","type":"api-call-service","z":"6834cbba8bef9da4","name":"Is High","server":"e6b2fc324dca9de0","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{ entity_id }}"],"data":"{\"brightness\":0}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1360,"y":200,"wires":[[]]},{"id":"e6b2fc324dca9de0","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":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false},{"id":"55860a44a1511913","type":"mqtt-broker","name":"core-mosquitto","broker":"core-mosquitto","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]