Is there some way to have the hold action of a lovelace button increase the mediaplayer volume or light brightness as long as you hold it?
No and yes.
There is no release event in Lovelace, so it is not possible to tell when you have released a control using just the core dashboard elements.
However a work-around using node-red, the custom button card and some input numbers was posted here: Hold action keep firing until I let go? - #7 by pallen
Is this functionality so rare that it’s not a standard feature?
I have seen some sort of light switches/home automation systems that are able to do this: tapping for on/off and holding to dim/brighten.
You can do this with the custom:button-card.
For example:
hold_action:
action: call-service
repeat: 200
service: input_number.increment
service_data:
entity_id: input_number.temp_test
icon: mdi:arrow-up-bold-outline
size: 37%
tap_action:
action: call-service
service: input_number.increment
service_data:
entity_id: input_number.temp_test
type: custom:button-card
Hi @VDRainer, thanks for this tip!
Can you please tell me how to integrate a light into your code?
The input number does change but just adding an entity does not seem to be it.
I have checked the GH page for that card and lots of examples but nothing helps.
I’m using this for media_players volume and Temperature settings of thermostats, but found some code that i played with a while ago.
Two automations, one to set the light and one to set the input_number if the light changes.
automation:
- alias: updown_button_test_get
trigger:
platform: state
entity_id: input_number.button_test
action:
service: light.turn_on
data_template:
entity_id: light.your_light
brightness: "{{ trigger.to_state.state | int(0)}}"
- alias: updown_button_test_set
trigger:
platform: state
entity_id: light.your_light
action:
service: input_number.set_value
data_template:
entity_id: input_number.button_test
value: >
{% if state_attr('light.your_light', 'brightness') %}
{{ state_attr('light.your_light', 'brightness') }}
{% else %}
0
{% endif %}
You need to adjust the repeat value of the button and the max, min, step values of the input_number depending of your light.
Hi @VDRainer, I’m back on this issue, I did not manage to get it working…
This is my custom button:
hold_action:
action: call-service
repeat: 200
service: input_number.increment
service_data:
entity_id: input_number.temp_test
icon: mdi:arrow-up-bold-outline
size: 37%
tap_action:
action: call-service
service: input_number.increment
service_data:
entity_id: input_number.temp_test
type: custom:button-card
entity: light.ll1
Automation
- id: '1653839036292'
alias: 'Livingroom: Dimmer Light'
description: ''
trigger:
- platform: state
entity_id:
- light.ll1
condition: []
action:
- service: input_number.set_value
data_template:
entity_id: input_number.temp_test
value: >
{% if state_attr('light.ll1', 'brightness') %}
{{ state_attr('light.ll1', 'brightness') }}
{% else %}
0
{% endif %}
mode: single