Minimote and fan speed toggle/speed change

I’ve gotten my mimimotes included into my network and can toggle lights, etc. based on some of the configuration setups I’ve found here on the forums and in the HA documentation. I’ve now moved on to trying to toggle my fan speed based on it’s current state. I’ve built the following automation based on what @rowdybeans, @Taras, and @finity had suggested to others on this post . Here’s the automation:

# Minimote #1 - Button #2
# Fan Speed Low/Med/High
  - id: mini_1_2_held
    alias: 'Minimote #1 Held - Bedroom Fan Speed Increase/Decrease'
    trigger:
      - platform: event
        event_type: zwave.scene_activated
        event_data:
          object_id: zwave.aeotec_minimote1
          scene_id: 4
    action:
     - service: fan.set_speed
       entity_id: 
         fan.bedroom_fan
       data_template:
        speed: >
          {% if (state_attr('fan.bedroom_fan', 'off')) %}
            low
          {% elif (state_attr('fan.bedroom_fan', 'low')) %}
            medium
          {% elif (state_attr('fan.bedroom_fan', 'medium')) %}
            high
          {% else %}
            low
          {% endif %}

Unfortunately it’s only partly working and I’m probably overlooking something simple. Basically, regardless what speed the fan is running it always goes to “low” instead of stepping from one level to the next and then back to low from high. Anyone?

Are you sure the state of the fan is changing from “off”?

If it always shows as off then you’ll never get past the first ‘if’.

state_attr is the wrong function. That turns into something like the value of states.fan.bedroom_fan.attributes.off, etc. off is not a state attribute. The fan speed is the speed attribute of the entity, so you need is_state_attr('fan.bedroom_fan', 'speed', 'off'), etc.

2 Likes

Good catch. Totally missed that.

So the issue is the 'if’s are miscoded and never true so it reverts to the ‘else’.

Yeah, all of the state_attr() functions are going to evaluate to None which is false.

Thanks, I’ve made the change but can’t test it at the moment. Something about the wife not being thrilled with the husband turning the bedroom fan on in the middle of winter while she’s sleeping! :wink:

OK, I did a test last night and it’s working now. Thank you @freshcoast and @finity