Dyson switch - Turned on, auto mode & speed selection

Recently @tom_l helped me in writing a switch for my Dyson fan. I have created a new topic as it is going down another path.

The switch he created was as follows:

switch:
  - platform: template
    switches:
      oscillation:
        friendly_name: Oscillation
        value_template: "{{ is_state('fan.bedroom', 'on') and is_state_attr('fan.bedroom', 'oscillating', true) }}"
        turn_on:
          service: fan.oscillate
          data:
            entity_id: fan.bedroom
            oscillating: true
        turn_off:
          service: fan.oscillate
          data:
            entity_id: fan.bedroom
            oscillating: false
        icon_template: >
          {% if is_state('fan.bedroom', 'on') and is_state_attr('fan.bedroom', 'oscillating', true) %}
            mdi:arrow-left-right-bold
          {% else %}
            mdi:minus-circle-outline
          {% endif %}

This works most of the time, however, it turns out that the sensor/state reports differently depending on the mode the fan is in. So if it is turned on with a manually selected speed, then:

fan.bedroom state is on
fan.bedroom auto_mode is false

If the fan is turned on and in auto mode:

fan.bedroom state is off
fan.bedroom auto_mode is true

If the fan is not on at all

fan.bedroom state is off
fan.bedroom auto_mode is false

So I think that the above code needs minor modification, however, I am just unsure how to add the OR statement or what is required to check two states to give the required answer. It looks like two sections need to be updated:

 value_template: "{{ is_state('fan.bedroom', 'on') and is_state_attr('fan.bedroom', 'oscillating', true) }}"

{% if is_state('fan.bedroom', 'on') and is_state_attr('fan.bedroom', 'oscillating', true) %}
            mdi:arrow-left-right-bold

So, finally, to my actual question :slight_smile: How do I add into the above code to also check if the fan is in auto_mode as well, because this also indicates that it is turned on. Not just the state.

Hopefully this makes sense

value_template: "{{ ( is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true)  ) and is_state_attr('fan.bedroom', 'oscillating', true) }}"
1 Like

2020-01-02 16:18:57 ERROR (MainThread) [homeassistant.components.hassio] Invalid config for [switch.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['switches']['oscillation']['icon_template']. Got "{% if is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true) ) and is_state_attr('fan.bedroom', 'oscillating', true) %}\n mdi:cached\n{% else %}\n mdi:minus-circle-outline\n{% endif %}\n". (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/template/

:frowning:

You missed a ā€œ(ā€ somewhere. What I wrote has matching pairs. Try cutting and pasting it.

1 Like

Strange, I copy/paste originally and it didnā€™t work. So I removed one of the brackets and didnā€™t work. Copied again & worked. Go figure.

It appears that it works now, thanks.

The main fan icon, which is in ui-lovelace still says off. Originally it was this code:

          entities:
            - entity: fan.bedroom
              tap_action:
                action: toggle

Iā€™ve changed it to this, however still isnā€™t working.

            - entity: fan.bedroom
              tap_action:
                action: toggle
              icon_template: >
                {% if is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true) %}
                  mdi:fan
                {% else %}
                  mdi:minus-circle-outline
                {% endif %}

Any ideas what I missed?

Entity buttons do not support icon templates, see the documents for supported options:

So just create another switch entry like the others for this?

Thatā€™s one way. There are other custom cards you can use to modify Lovelace but Iā€™d stick with what you know for now.

You mean stick with what you know ? ha

      fanpower:
        friendly_name: "Fan Power"
        value_template: "{{ ( is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true)  )}}"
        turn_on:
          service: fan.turn_on
          data:
            entity_id: fan.bedroom
            **oscillating: true**
        turn_off:
          service: fan.turn_off
          data:
            entity_id: fan.bedroom
            **oscillating: false**
        icon_template: >
          {% if is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true) %}
            mdi:fan
          {% else %}
            mdi:minus-circle-outline
          {% endif %}

Iā€™ve changed most of one of the switches I already have. Except, the oscillating part (true/false) is wrong. The command fan.turn_on and fan.turn_off is just a service that you call and does not appear to have any value to input there

For those interested. It appears that solution for that part was:

      fanpower:
        friendly_name: "Fan Power"
        value_template: "{{ ( is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true)  )}}"
        turn_on:
          service: fan.turn_on
          data:
            entity_id: fan.bedroom
        turn_off:
          service: fan.turn_off
          data:
            entity_id: fan.bedroom
        icon_template: >
          {% if is_state('fan.bedroom', 'on') or is_state_attr('fan.bedroom', 'auto_mode', true) %}
            mdi:fan
          {% else %}
            mdi:minus-circle-outline
          {% endif %}

Next on my list is to get the fan speed sensor to select the speed on click. I will do some searching to work out which tap_action that will be.

Once I have that done, I should be done and I can post the whole lot for anyone interested :slight_smile:

1 Like

Have a read of this:

For me the Oscillation switch is in the entity. Also the speed selection. I donā€˜t need to create separate switches.

It looks like the Dyson fan integration isnā€™t reporting the correct state when it is in ā€˜autoā€™ mode. How do I report that for the team to look at?

@Krocko So what is the code for you from those screenshots?

It is the Dyson integration.

But for that are you just using this to display it in lovelace?

            - entity: fan.bedroom
              name: Fan

Donā€˜t understand, sorry.
I have added the fan to an entity card.
This is the 'more infoā€˜ view. You get this, if you tap on the entity name (not the toggle) in this card.

The screenshot you posted. Is that after you click something? If so, what code in Lovelace have you used to get that card

Thank you! Indeed your works is very interesting!

Hi @DrSpaldo, have you made some progress over this?
Have you also created switches or at least UI buttons for night mode and auto mode?