volume_control_4_magic_cube_and_other_things - 2023-12-07 by SirGoodenough
This script was invented to be used with my Magic Cube Blueprints. I released it as a standalone Script Blueprint because because of requests to extend the function of my BP's with how to convert cube rotation to volume in other places. Research found me this Post from Petro which had a very elegant solution to the problem, It was very easy decision to adopt it here.
To use this blueprint, install it from the source in the normal way. After that add your unique name for the Script, and add an icon and change the entity_id if desired. You should only need to run the blueprint once, as you will be calling the unique name/entity you added above to use the code and provide action data. This script has one !input in the Blueprint screen to set the sensitivity of the rotation to volume changes. 30 seemed about right, but adjust as needed.
Because all the data is added to control the action live at each use this is the only !input. This requires you call this generated script wth 2 data values when you want it to run. One is a positive or negative number between 360 and -360 that in the original, represents the input angle from the cube movement. The other data point is the entity of the media_player that you are trying to control.
NOTE: the trigger variable below will be different for Z2M and ZHA and others. Look at my documentation for that cube integration help if you need it.
Sample call / use of this script for ZHA:
yaml - service: script.cube_dimmer_control_bp data: angle: '{{ trigger.event.data.args.relative_degrees | default(0.1) | float(0.2) }}' mp: media_player.farg
Sample call / use of this script for Z2M:
yaml - service: script.cube_dimmer_control_bp data: angle: '{{ trigger.payload_json.action_angle | default(0.1) | float(0.2) }}' mp: media_player.farg
🗿Notice👮🏿♂️:
-
Copies of the original Blueprint that were converted via the 'Take Control' feature or other means are officially not supported by me.
-
I may or may not be able to support you when you have a problem after you make changes to my code, as some of the code is no longer mine.
-
I & my license also require attribution as a link back to the original should you use this code in your own creation.
-
Here is a link to my license & the original github post expected to be followed & referenced as attribution should you use this code elsewhere.
Import to Home Assistant
Click to import this blueprint directly into your Home Assistant instance.
Configuration
Requires 1 input to configure
Source Code
View on GitHubDetails
Explore More
Related Blueprints
More button actions automations you might like