I have made a slider card that allows me to send a speed integer value to a ceiling fan, in a round-about way. Due to limitations of that fan’s integration, it has to go through Alexa Media Player (AMP). It works well, with an “input number” helper saving the value of the fan setting and then sending it via a script.
alias: Set fan to variable and run
sequence:
- target:
entity_id: media_player.sample_echo_dot
data:
media_content_type: custom
media_content_id: set fan speed to {{ states('input_number.fanspeed') | int }}
action: media_player.play_media
description: Set ceiling fan to variable {{ fanspeed }}
icon: mdi:fan-auto
I have also made a series of pre-set buttons, to make it easier for others in my household, to activate the fan.
Each button uses a separate script that does not have variables, it just sends the speed number via media_content_id to AMP, such as:
alias: Set fan 65
sequence:
- target:
entity_id: media_player.sample_echo_dot
data:
media_content_type: custom
media_content_id: set fan speed to 65
action: media_player.play_media
description: ""
One issue with this is that the slider card does not update with the fan speed sent by the pre-set button.
I would like to modify these pre-sets so that it first sets input_number.fanspeed to the preset speed, and then continues with the AMP command using that variable.
I tried modifying a pre-set script by adding a “define variables” action prior to running the variable script, but I am not suceeding, mostly due to my significant knowledge gap on if/how to set input_number.fanspeed outside of the slider card.
Would appreciate any guidance on what seems to be a simple variable programming issue.
alias: Set fan to variable and run
sequence:
- action: input_number.set_value
data:
value: "{{ fanspeed | int(0) }}"
target:
entity_id: input_number.fanspeed
- target:
entity_id: media_player.sample_echo_dot
data:
media_content_type: custom
media_content_id: set fan speed to {{ fanspeed }}
action: media_player.play_media
description: Set ceiling fan to variable fanspeed
icon: mdi:fan-auto
Then, in your card, you will need to pass the variable fanspeed to the script. The exact configuration will depend on how you call the script.
Thank you, that’s exactly what I needed to get me on my way!
Works great now with this new series of presets I’ve created.
sequence:
- action: script.set_fan_to_variable_and_run_newer_way_with_fanspeed
data:
fanspeed: 60
alias: Set fan 60 (new way)
description: Set ceiling fan speed to 60 (and set fanspeed variable also)
icon: mdi:fan-chevron-down
Interesting idea. I described my journey with this particular model fan controller (fanimation) in this thread:
While the native phone app offers many options, its only HA integrations have to go through Alexa/Smartthings/Google Home. Smartthings/Google Home only has ON/OFF and slow/medium/fast, but somehow Amazon/Alexa allows fan percentages. Also various Smartthings integrations skipped the fan module entirely.
In essence: Only through smartthings can HA see the on/off state of the fan. Only through AMP can I affect fan percentage. There is no way to read fan percentage, only the last percentage sent via AMP.
I might try to integrate these scripts into the fan template as a learning experience. Only on/off + percentage speed would apply, which is where we are now.