Glance card item calling service

I’ve been searching and trying options, but, my brain has melted. I am sure I am missing something simple. Any help would be appreciated.

I have a glance card in ui-lovelace.yaml for the Dyson fan in the kids bedroom. The two sensors at the top are working fine (I am not sure how to rename, but that is for another time - name and friendly_name don’t do anything).

The turning on of the fan works fine (option 3)

But, I cannot for the life of me work out how to call a service for the oscillation.

In the dev tools, service area I have this:

service: fan.oscillate
entity_id: fan.bedroom
oscillating: true

This is the code so far, I have tried a few different options than the below without success:

        entities:
          - sensor.bedroom_humidity
#              friendly_name: Humidity
          - sensor.bedroom_temperature
#              friendly_name: Temperature
          - entity: fan.bedroom
            tap_action:
              action: toggle
          - entity: fan.bedroom
            tap_action: #call-service
              action: call-service
              service: fan.oscillate
              service_data:
              oscillating: true

Well, I figured out the naming problem. Just not the calling service/oscillation

        entities:
          - entity: sensor.bedroom_humidity
            name: "Humidity"

Probably like this:

        entities:
          - sensor.bedroom_humidity
#              friendly_name: Humidity
          - sensor.bedroom_temperature
#              friendly_name: Temperature
          - entity: fan.bedroom
            tap_action:
              action: toggle
          - entity: fan.bedroom
            tap_action: #call-service
              action: call-service
              service: fan.oscillate
              service_data:
                entity_id: fan.bedroom
                oscillating: true

Thanks for the reply @tom_l

Unfortunately that didn’t work. I get another error:

Failed to call service fan/oscillate. extra keys not allowed @ data['entity']

That’s because it should be entity_id not entity in the service data. Compare what I wrote to yours.

1 Like

@tom_l Apologies, I didn’t notice the extra _

That made the function send through and it worked. Which is good, thanks :slight_smile:

I guess it may not have been exactly what I was after… Now I am thinking of a toggle for the oscillating and an indication of the status of such. Currently it has the yellow light on to match the fan on/off status, the same as entry 3, rather than the status of the oscillating.

Can I push the friendship for any ideas on what the best way would be to do that?

I don’t really understand what you are asking.

Sorry @tom_l

When you press the fan power button as it is a toggle action, it turns if on & off. Changing the colour depending if it is on or off.

I would like the oscillating to function in the same way. However, because it was a specific service, I create the thread asking how to set it to true, which you figured out.

However, now that I see how it is functioning, I would like the oscillating to also behave the same way as the power button does. I am just not sure how you would write that when it is a service function and act in the same way.

Does that make more sense?

Ok, looking at the developer tools states menu, is there an attribute of the fan that indicates if it is oscillating?

Within developer tools -> states -> fan.bedroom

state:
on

Attributes:
speed: 2
speed_list: AUTO,1,2,3,4,5,6,7,8,9,10
oscillating: true
night_mode: false
auto_mode: false
friendly_name: Bedroom
supported_features: 3

Then the easiest way would be to make a template switch and add that to the glance card.

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 %}

Feel free to choose better icons.

1 Like

Thank you very much for the reply. I will give it a go now. Just have to work out where to slip it in :wink:

Wherever your other switches are defined, don’t include the first line (switch:), you will likely already have it somewhere.

1 Like

Sorry, I am learning so trying to keep up. I don’t have a switches.yaml. Do you mean create one of them or put them into the configuration.yaml, put all the switches you helped create in that. Then in the ui-lovelace.yaml reference it within the glance card? ie. switch.Oscillation

In your configuration yaml.

switch:

(your switches here)

Or

switch: include switches.yaml

In which case put your switches in switches.yaml instead.

NOTE: if using this method do not put switch: at the top of the switches.yaml file.

1 Like

I’ve just put them into the configuration yaml

When I reference them now in the ui-lovelace is it an action toggle or something else?

          - entity: switch.oscillation
            name: "Oscillation"
            tap_action: toggle

I’ve tried the above and it doesn’t appear to be displaying the correct status or do anything on press

Did you run a configuration check and restart?

Tap action toggle is correct.

Yep, it says valid but something isn’t working :frowning:

Actually. They are bringing up the info in press and not doing the action I specified

Try:

    tap_action:
      action: toggle
1 Like