Thanks for the effort on this. I just got it working, sort of on my HA installation.
The problem I’m having is in the blueprint line 390~.
I’m using two instances of Z2M because of covering two separate buildings. One named -1 and the second -2.
Looks like it’s stripping that to go with “zigbee2mqtt.” I can get manually change it to “zigbee2mqtt-1” and get it to work in one instance. Can the full path be carried over to the command path?
I’m a nube with the code. Sugestions?
Les
- variables:
command_path: "{% if repeat.item in command_path_map %}\n {{ command_path_map[repeat.item]
}}\n{% else %}\n zigbee2mqtt-1/{{ device_attr(repeat.item, \"name\") }}/set\n{%
endif %}"
There isn’t a way to get the command path in the script, so I had to hard-code the MQTT path on the line you found.
You can edit the blueprint, but then it would only work for one of the Z2M instances.
You could also copy the blueprint and have 2 instances of it and create a script instance for each blueprint. But that seems kind of wasteful.
There is a third solution that is built into the blueprint script instance. You can use the “Command Path Map” field for a custom path per-light entity:
@zanixmechanix I reused a lot of your code for another blueprint that uses ZHA and takes your idea of iterating through targets (such as areas, devices, entities) to get all switches found that correspond with the target. Also took the opportunity to optimize a few things and make the script faster. Would love your feedback! Thanks.
I see the biggest changes are the payload construction was moved out of the repeat loop and the removal of the “entity_id” parameter (which is only there since I made this script initially without the target options).
Not having to rebuild the payload on each loop would be slightly faster. Thanks for catching that, now I’ll have to update my blueprint.
No thank you @zanixmechanix . Your code saved the day! I’d been looking for a way to achieve a multicast to all switches at once and your iteration idea is for sure the closest thing to it. In essence, here is what I modified:
Converted from Z2M to ZHA
1.1 Command_path removed
1.2 Changed integration: zha
1.3 service: mqtt.publish replaced by zha.issue_zigbee_cluster_command
Removed the Off values from most config options except from Effect, to generate 1 standard way to stop an animation and avoid confusion
Changed several Default values so that the script does a bare minimal animation with bare minimal configuration
Remove the depricated Entity_ID parameter and extra logic
Took the payload building out of the loop for faster iteration
The rest, is basically the same! Could this be the ZHA alternative you suggest in this post instead?
I am working on getting my porch light LED bar to turn red whenever I have the door unlock, and green whenever the door is locked. I am trying to just call the service after I created the script but nothing happens. Is this blueprint still supported and working? Many thanks!
I’m going to apologize upfront because I’m sure that I’m missing something and my issue is user error.
I found and just installed the blueprint this evening after trying to figure out how to set LEDs 1-3 to blink when my alarm is armed. By the way THANK YOU for creating this!
However the script doesn’t seem to be working and I’m getting an error in my scripts.yalm file.
If not, you can check one other possibility.
Does the name of the switch in Home Assistant match the name in Z2M?
If not, you will need to override the command path when calling the script.
Find the command path
Settings > Devices > MQTT (click on “## Devices”) > DEVICE NAME
Click on “More Info” and expand “Payload”
Find command_topic and copy the value
Enter the entity_id of the light entity and the command_topic copied from the device and paste it into the “Command Path Map” field
Example:
No errors in the log (matching the device or script). I found some other things to look at but that’ll be for another time.
Getting the command_topic was exactly what I needed!
I bet that is because I changed the device type to be a fan instead of it being a light or a switch.