Lovelace button to change a number value?

I have a servo glued to the power button of my air conditioner, which is hooked up to a Wemos D1 Mini flashed with ESPHome’s servo component. I want to be able to click a button on my dashboard that will call an automation that will simply turn the servo to 85% momentarily then back to 75%. All the automation needs to do is change the value of the number entity ‘servo_control’.

Right now I have a number entity called servo_control which is being affected by a slider (and works) but is too cumbersome to slide the slider to 85% then quickly down to 75% to turn off or on the AC. This is what I have so far for the automation but it does nothing.

lovelace button code

type: button
tap_action:
  action: call-service
  service: automation.trigger
  service_data:
    entity_id: automation.airconditionertoggle

in the automations.yaml file

automation:
  - alias: AC Press
    trigger:
      entity_id: automation.airconditionertoggle
    action:
      service: number.set_value
      entity_id: number.servo_control
      value: 75 %

You don’t need a trigger as you are calling the the action manually with the button, so use a script (automations are just scripts with triggers). Also do not include the unit when specifying the value to set the number to.

type: button
tap_action:
  action: call-service
  service: script.ac_off
script:
  ac_off:
    sequence:
      - service: number.set_value
        target:
          entity_id: number.servo_control
        data:
          value: 85 
      - delay: 1 # in seconds, adjust this as required
      - service: number.set_value
        target:
          entity_id: number.servo_control
        data:
          value: 75 

You could do this all in ESPHome and just expose the button that calls the actions.

Great! This worked perfectly. Thanks a ton

1 Like

Hi tom ,

very helpful answer .

Can you explain your last sentence , what do you mean expose a button in esphome ? Thank you

Stavros

BY using this:

Thank you for the quick answer