Template number (e.g., for volume control)

I’ve had an idea that combines an input_number with the template features of a template light, cover, etc. I think it would be ideal for tracking and controlling volume, but I’m sure there are other uses. It’s configuration options would include:

  • value_template: a template for determining its current value
  • set_value: a service that sets something to value so that value_template will now evaluate to value (assuming you set it up correctly!)

Example

Let’s say you have template_number.volume that tracks and controls the volume of some media player.

  1. Initially, the volume of the media player is 0.5, so the value of template_number.volume is also 0.5.
  2. You change the volume of the media player to 0.7, so now the value of template_number.volume is 0.7.
  3. You use the service template_number.set_value to set template_number.volume to 0.3. This calls a service that sets your media player’s volume to 0.3, and as a result the value of template_number.volume is now 0.3.

This would allow you to have a slider that updates when the volume level changes and that changes the volume level when you move the slider. I think that people would find this useful, and it’s a much cleaner approach than using an input_number and an automation.

Would a media_player template be a viable solution to accomplish what you’re trying to do? I feel like it would give you a lot more functionality than just a simple volume template.

Yes and no. It would give more functionality for media players, but it’s less general. I submitted a pull request but it didn’t get accepted. I still think that people would find plenty of uses for this if it were made available.

For sure I vote for this, because I just run into the same issue - but not with a media controll.

Example:
The integration for my Skoda EV does provide a service to change the charging limitation.
I would like to do this from my dashboard - I know from another integration, that NUMBER entities will be shown as a Slider by default…
So I thought, I could do that with a number-entity template, and reflect the state to the state for the service (Set-State) … and this is how I found this Feature Request… which makes me thinking, that my Idea is currently not possible… :frowning:

From what you have described, a template number should cover your situation. It will create an entity that acts like an input number in the frontend, but , like an automation, runs a sequence of actions you define when you change the value.

1 Like

thanks :slight_smile:
Then - I have to digg deeper into the number templates :slight_smile:

HI @Didgeridrew,
maybe you are able to help me a bit with how to create the number template?

This is the service (in yaml)

service: skodaconnect.set_charge_limit
data:
  device_id: 07ffbc26fc8a24e969e8c418ecf1146a
  limit: 30

How do I write the number template?

template:
  - number:
      - name: set_iv60_max_charge_limit
        set_value: 
          service: skodaconnect.set_charge_limit
            target:
              device_id: 07ffbc26fc8a24e969e8c418ecf1146a
        .....

I am not sure - it seems that the editor does not like the device_id… it is awaiting an entity_id instead, but I don’t know how to get this … :frowning:

  1. You’re missing a couple required values. You must set a value for state and step:. Step influences how finely you can adjust it from the frontend as well as what will happen if you call the decrement or increment services on your number.
  2. Your two service examples don’t match. Which is correct?
  3. The indents in the template number are incorrect.
  4. If your range is not 0-100, you need to set min and max.
template:
  - number:
    - name: Set IV60 Max Charge Limit
      state: ?
      set_value:
        - service: skodaconnect.set_charge_limit
          data:
            limit: "{{ value }}"
            device_id: 07ffbc26fc8a24e969e8c418ecf1146a
      step: ? 
      min: ?  (optional, default: 0.0)
      max: ? (optional, default: 100.0)

Thanks :slight_smile:
I was a bit confused, because the editor throw a couple of errors - therefore, I haven’t done all things (it thrown an error that device_id was not valid here…

It seems, that the template itself is working - but I am not sure, if the action will be triggered after changing the value.
I’Ve tried it a few times, but I could not see any change within my skoda app… but when I do the change in the service directly - and hit the button for running the service - then the change will be reflected after a couple of seconds in the app.

this is the template I am using right now:

  - number:
    - name: Set IV60 Max Charge Limit
      state: "{{ states('sensor.enyaq_iv60_minimum_charge_level') }}"
      set_value:
        - service: skodaconnect.set_charge_limit
          data:
            limit: "{{ value }}"
            device_id: 07ffbc26fc8a24e969e8c418ecf1146a
      step: '10' 
      min: '10'
      max: '100'

the “state” was mentioned as required… it is the current charge limitation…

Anyway - I don’t want to spam this FR any further… thanks for your supprt :slight_smile: