Error numeric value?

Hi friends, I have energy sensors, when I restart it gives me these errors. How can I do. Thank you

Sensor sensor.prodotta_potenza_a has device class None, state class None and unit W thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class ‘str’>); Please update your configuration if your entity is manually configured, otherwise create a bug report.

template:
  - sensor:
    # SONDA A (PRELEVATA)
    - name: 'Prelevata Tensione'
      icon: mdi:power-plug
      unit_of_measurement: 'V'
      state: "{{ states('sensor.iammeter_voltage_a') }}"
      #availability: "{{ is_number(states('sensor.prelevata_tensione')) }}"
    - name: 'Prelevata Corrente'
      icon: mdi:power-plug-outline
      unit_of_measurement: 'A'
      state: "{{ states('sensor.iammeter_current_a') }}"
      #availability: "{{ is_number(states('sensor.prelevata_corrente')) }}"
    - name: 'Prelevata Potenza A'
      icon: mdi:home-lightning-bolt-outline
      unit_of_measurement: 'W'
      state: "{{ states('sensor.iammeter_power_a') }}"
      #availability: "{{ is_number(states('sensor.prelevata_potenza_a')) }}"
    - name: 'Prelevata Importata A'
      icon: mdi:transmission-tower-import
      unit_of_measurement: 'kWh'
      state: "{{ states('sensor.iammeter_importenergy_a') }}"
      #availability: "{{ is_number(states('sensor.prelevata_importata_a')) }}"
    - name: 'Prelevata Esportata A'
      icon: mdi:transmission-tower-export 
      unit_of_measurement: 'kWh'
      state: "{{ states('sensor.iammeter_exportgrid_a') }}"
      #availability: "{{ is_number(states('sensor.prelevata_esportata_a')) }}"
    - name: 'Prelevata Reattiva A'
      icon: mdi:chart-ppf
      unit_of_measurement: 'VAR'
      state: "{{ states('sensor.iammeter_pf_a') }}"
      #availability: "{{ is_number(states('sensor.prelevata_reattiva_a')) }}"

I have plenty of template sensors which may be “None” “unknown” on HA startup.
As a result my log is flooded by these warnings.

Stop commenting out your availability templates.

Also set appropriate device and state classes.

In my case I have device_class & availability specified:

  - sensor:
      - name: xxxxxxxxx
        device_class: battery
        unit_of_measurement: %
        state: >-
          {{ state_attr(....,"battery_level") }}
        availability: >-
          {{ not states(......) in ["unavailable","unknown"] }}

which seem to work perfect - except these warnings on HA startup.

this is how i fixed it thanks

template:
  - sensor:
    # SONDA A (PRELEVATA)
    - name: 'Prelevata Tensione'
      icon: mdi:power-plug
      unit_of_measurement: 'V'
      #state: "{{ states('sensor.iammeter_voltage_a') }}"
      state: >
        {% if is_state("sensor.iammeter_voltage_a", "unknown") %}
          0.0
        {% else %}
          {{ states("sensor.iammeter_voltage_a") }}
        {% endif %}

No, like this:

template:
  - sensor:
    # SONDA A (PRELEVATA)
    - name: 'Prelevata Tensione'
      icon: mdi:power-plug
      unit_of_measurement: 'V'
      state_class: measurement
      device_class: voltage
      state: "{{ states('sensor.iammeter_voltage_a') }}"
      availability: "{{ states('sensor.iammeter_voltage_a')|is_number }}"

However this does beg the question, why are you just copying the state of a sensor in a template?

Thanks for the reply.
Because the sensor could change one day and I don’t feel like writing everything.

So I replace with your code that you posted?

Thanks again

There is absolutely no reason to do this then.

When or if you replace the sensor you simply delete the old sensor and rename the new one’s entity_id to match the old. In one place. Job done.

There is a relatively new integration method here, but it is through hacs.
Here is the video tutorial:

  1. [Add a 3phase power meter(WEM3080T) in Home Assistant by HACS-beginner (youtube.com)](https://www.youtube.com/watch?v=QpmpWED-85g)
  2. [IAMMETER`s Wi-Fi energy meter in Home Assistant custom component(HACS) -modbus/tcp (youtube.com)](https://www.youtube.com/watch?v=_bh3gKOAfA8)