Files
GarminHomeAssistant/examples/Numeric.md
StumblingGamer 17690d4349 Proposing changes to documentation and JSON Schema
Added proposed documentation section explaining Numeric data object and also updated JSON schema to match changes.

I tested the numeric example with tap_action.data in the documented web editor. The current schema did not appear to reject the field,
likely because numeric tap_action does not currently forbid additional properties at that nested level. I still added data explicitly
to the numeric schema so it is documented, discoverable, and type-checked as an object.
2026-06-23 11:12:00 -04:00

7.3 KiB

Home | Switches | Actions | Templates | Numeric | Glance | Background Service | Wi-Fi | HTTP Headers | Trouble Shooting | Version History

Numeric

Provides a number picker in order to adjust a numeric value of an entity.

Thermostat

An example using a thermostat as a numeric menu item.

{
  "name": "Heating",
  "content": "{{ ' %.1f' | format(state_attr('climate.room','temperature')) }}",
  "type": "numeric",
  "entity": "climate.room",
  "tap_action": {
    "action": "climate.set_temperature",
    "picker": {
        "step": 0.5,
        "min": 10,
        "max": 30,
        "attribute": "temperature",
        "data_attribute": "temperature"
    }
  }
}

This needs some explanation. The tap_action object needs a picker object to specify the numeric menu item's behaviour. The picker object is described in the table below.

Field Purpose Mandatory
step The increment or decrement step size. Yes
min The minimum value the numeric entity can take. Yes
max The maximum value the numeric entity can take. Yes
attribute The attribute on the entity that holds the state to be read. No
data_attribute The attribute on the action call that sets the state. Yes

It may well be the case that often attribute and data_attribute are the same attribute, as with this example.

Additional Action Data

The tap_action object may also include a data object for fixed service call parameters. When the picker value is selected, the application merges the picker value into this data object using data_attribute.

For example, a light brightness picker can request a HomeAssistant transition while still using the picker value for brightness.

{
  "name": "Lounge Brightness",
  "content": "{{ ((state_attr('light.lounge','brightness') | int(0) / 255) * 100) | round(0) }}%",
  "type": "numeric",
  "entity": "light.lounge",
  "tap_action": {
    "action": "light.turn_on",
    "data": {
      "transition": 2
    },
    "picker": {
      "step": 5,
      "min": 0,
      "max": 255,
      "attribute": "brightness",
      "data_attribute": "brightness"
    }
  }
}

The resulting action data sent to HomeAssistant contains both the fixed transition value and the selected brightness value.

Helper

You might define a "helper" entity as follows in HomeAssistant:

In this case, the state is the actual value, so the template uses states(..) instead of state_attr(..), you must not set the optional attribute value in the JSON definition so that the application uses the correct template internally for querying the HA server for its present value. Your own template definition in the content field will need to follow suit too. The data_attribute must be set to value for the action call that sets the chosen value from the number carousel.

{
  "name": "My Float",
  "content": "Currently {{ states('input_number.my_float') }}",
  "type": "numeric",
  "entity": "input_number.my_float",
  "tap_action": {
    "action": "input_number.set_value",
    "picker": {
      "step": 0.5,
      "min": -10.0,
      "max": 10.0,
      "data_attribute": "value"
    }
  }
}

Amplifier

The complication here is this amplifier uses one scale for changing the value, a range 0.0 to 1.0, and another to render the volume on the display, dB. So the template does some scale conversion, but the number picker has to use the 0.0 to 1.0 range which is annoying.

{
  "name": "Amplifer Volume",
  "content": "{{ '%.1f' | format(state_attr('media_player.amplifier','volume_level') * 100 -80) }} dB ({{ state_attr('media_player.amplifier','volume_level') }})",
  "type": "numeric",
  "entity": "media_player.amplifier",
  "tap_action": {
    "action": "media_player.volume_set",
    "picker": {
        "step": 0.005,
        "min": 0.2,
        "max": 0.6,
        "attribute": "volume_level",
        "data_attribute": "volume_level"
    }
  }
}

The above is a little awkward to change the volume as the picker's scale is unfamiliar. To make life easier you might choose to implement a "Template number" in HomeAssistant as defined in the following dialogue box.

For copy and paste, the Jinja2 fields are as follows:

  1. Template rendering with conversion to dB:
{{ state_attr('media_player.amplifier','volume_level') * 100 -80 }}
  1. Conversion from dB to range 0.0 to 1.0:
{{ (value+80)/100 }}
  1. Availability template:
{{ not is_state('media_player.amplifier','unavailable') }}

As an alternative to using the GUI, the following can be pasted into HomeAssistant's configuration.yaml:

template:
  - number:
      - name: "Amplifier dB"
        unique_id: "<Generate Unique ID>"
        unit_of_measurement: "dB"
        state: "{{ state_attr('media_player.amplifier','volume_level') * 100 -80 }}"
        availability: "{{ not is_state('media_player.amplifier','unavailable') }}"
        set_value:
          - action: media_player.volume_set
            target:
              entity_id: media_player.amplifier
            data:
              volume_level: "{{ (value+80)/100 }}"
        step: 0.5
        min: -60
        max: -15
        icon: mdi:audio-video

We noticed some schema checking errors when we tried this, but the YAML above is consistent with the HA Template support pages, and this code does correctly create the number template as required.

The JSON menu definition can now use dB with the new template number as follows.

{
  "name": "Amplifier Volume",
  "content": "{% if is_state('media_player.amplifier','unavailable') %}Off{% else %}{{ '%.1f' | format(states('number.amplifier_db') | float) }} dB{% endif %}",
  "type": "numeric",
  "entity": "number.amplifier_db",
  "tap_action": {
    "action": "number.set_value",
    "picker": {
        "step": 0.5,
        "min": -60.0,
        "max": -15.0,
        "data_attribute": "value"
    }
  }
},

Trouble Shooting

Specific to this menu item:

  1. If the number picker does not initialise with the correct value, amend the attribute field. Just because your template renders does not mean the application has extracted the numeric value as the content template is rendered on the HomeAssistant server.

Credits

With thanks to Tom Michel, @thmichel for contributing this solution.