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?