How to create a number entity (not input_number)

I found this information about HA related to number entity:

But I don’t see (or understand) how to create one. The input_number is working but it has that slider bar on top. I don’t want to be able to change the value by hand. I need a place to store a number coming from another source. Can someone show me an example on how to create a number entity? It is not part of the HELPER.

Numbers are for integrations.
If it comes from another source then you should be able to use a sensor.

hum! OK, that is what I thought but… not sure how. See I entered this in the configuration.yaml:

 - platform: template
   sensors:
     front_temp:
       unique_id: 7272
       friendly_name: Température Extérieure
       value_template: >-
         {{ states('input_number.tempext') }}
       unit_of_measurement: '°C'
       device_class: temperature

But then, this is just a template using the input_number that I created. Also, I dont seems to be able to write into a sensor from an external source using REST API command. Sorry if I’m not 100% clear… I’m pretty new in this, and searching a lot.

Hello Guy Taschereau,

One way to create a number or any variable and it not be easily changeable is this.

ho wow… Thank you. This sounds a bit much for a neebe like me but I’ll give it a try.

Thanks again

You are not supposed to add the input number there it’s the “unknown” source.
It’s always better for everyone, especially the one asking, to post as much as possible of the details.

OK, Reading more about your suggested solution will not work I think. Here it is:

I have a system to monitor the energy usage in the house. This was my own built. It is amazingly accurate and I wish to keep it. But I would like to send the information from it to the HA system. I’m using the REST API command inside the python application. From the REST API, I see the list of services availables that includes the input_number, the number and several others. But nothing about variables.

Right now I’m able to do it all with the input_number but the slider bar is scaring me. I dont want to be able to change the value coming from my system within HA.

Not sure if that is enough info for you. Else, I’ll try to make something simple to show cause right now it is a mess. :wink:

1 Like

If the call to send data is from outside, then the solution would probably be a trigger based template sensor. The trigger would be the data coming in through a webhook. When doing it this way the sensor will be immutable from the HA user interface.

Note that the webhook example uses an automation. With a trigger based template sensor that automation isn’t needed, but the trigger is the same. Also note that while number entities are possible here, you probably do not want one. You do not need the services to set it anymore if the value comes from the trigger. Just use a simple sensor type and a unit of measurement.

1 Like

If it’s an API the just set it up as a rest sensor in HA.
No need for any Python.

ok, this sounds very interesting. Thank you guys. I’ll try this tonight when I come back.
Thanks again

OK, I think I need more info. I kept reading your message and re-read, but I cannot make it up entirely.
OK, I created a webhook trigger via an automation. From my old system, I can send the value. I see in the webhook that it gets triggered. But that is as far as I could go. I tried several different things but I don’t understand it all. And all the examples I find simply call a service like turn on. I don’t see how they take a value sent from the POST command into a sensor.

I dont know what the action should be.

Not sure to understand this. My webhook config looks like this:

id: '1737751982335'
alias: test webhook
description: ''
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: monid
conditions: []
actions:
  - action: number.set_value
    metadata: {}
    data: {}
mode: single

and the trace reports this error:

But I do supply the value: 23

this:
  entity_id: automation.test_webhook
  state: 'on'
  attributes:
    id: '1737751982335'
    last_triggered: '2025-01-25T01:25:20.725288+00:00'
    mode: single
    current: 0
    friendly_name: test webhook
  last_changed: '2025-01-25T01:26:37.493651+00:00'
  last_reported: '2025-01-25T01:26:37.493651+00:00'
  last_updated: '2025-01-25T01:26:37.493651+00:00'
  context:
    id: 01JJDH2TNNHQ4ZDS94FQTGTB7W
    parent_id: null
    user_id: null
trigger:
  platform: webhook
  webhook_id: monid
  json:
    value: '23'
  query:
    __type: <class 'multidict._multidict.MultiDictProxy'>
    repr: <MultiDictProxy()>
  description: webhook
  id: '0'
  idx: '0'
  alias: null

Am I way off??? :wink:

How is the action supposed to know that?

You are missing both the value and entity_id keys in the data section.

Using a number entity will not solve this issue. For almost all purposes input_number and number entities are exactly the same.


You need to create a trigger-based Template sensor that uses the data available in your webhook trigger.

#configuration.yaml

template:
  - trigger:
      - trigger: webhook
        allowed_methods:
          - POST
          - PUT
        local_only: true
        webhook_id: monid
    sensor:
      - name: Monid
        state: "{{ trigger.json.value }}"
1 Like

This is exactly my question. Look at my last post; You will see in the trigger “json: value: 23” How can this value transferred into a sensor?

I have no clue how to specify this in the webhook request.

You don’t. The number.set_value action requires a number entity as a target. Automations do not create entities. The entity must be created by an integration.

Using a number entity will not solve the problem you are trying to solve. As 5 of the previous comments have stated, you need to create a sensor.


You should be able to copy/paste the sensor configuration from my previous post directly into your configuration.yaml file to achieve your goal. Don’t forget that you will need to restart HA after altering the file to load the configuration changes.

ha!!! I see now. There was no need at all for the automation.

created the sensor (finally understood lol)

OK, Got it. It is working now. Except that I see now that a webhook has no return value. i.e. I have no way of finding out if HA received my data or not. I tried sending to an invalid name (for testing) and the result returned by the POST command is the same (200).

Thanks for the help!