Analog Input - Delete a part of the value I get from an analog input

Hi there!
I use Home Assistant from a few months to irrigate a grove.
I have a Denkovi device with 12 switch-relay, 8 analog inputs and 8 digital inputs.
I connected a sensor of pressure to an analog input, and that input gives me a value not numeric, for instance “1185 mV”.
I added a gauge card to my lovelace, and add the analog input to this gauge card, but I received a mesage similar to “the entity is not numeric”.
Despite the message, I can add the analog input, but it doesn’t work.
The problem is the last two chars of the value “XXXX mV”.
If I delete “mV” in Developer tools/Entity, then the card shows a grafic, just as I need, but when the value is updated I get again a number follows by “mV”, and the card stop working.
Anyone knows how I could delete that chars definetly?

Thanks in advance.

Welcome here Macario !

You should setup a template sensor then

template:
  - sensor:
    - name: analog_input_1_numeric
      unit_of_measurement: 'mV'
      state: >
        {{ states('sensor.analog_input_1')[:-2]|int }}

This new sensor.analog_input_1_numeric will be a sensor with a numeric value, and the correct unit of measurement. It will be updated as soon as your original sensor will be !
then add this new sensor to your gauge card.

Thanks a lot, SNoof85.

I’ve tried but it doesn’t work.
I think I skipped a previous step…
This is what I’ve done:
1- I’ve created the file “/config/sensors.yaml”, because it didn’t exist.
2- I’ve copy/paste the text you sent to me.
3- I’ve saved changes and cheked the server controls, and everything seems to be OK
4- I’ve restarted the server
5- I’ve tried to add the new sensor but it doesn’t appear… I can see every single sensor, but not this one

Is it possible that I have to change something in “/config/configuration.yaml”?
Any other file I should edit?

Just in case, this is right now the content of my “/config/configuration.yaml”:

**homeassistant:**
**  customize: !include customize.yaml**
**  name: Home**
**  latitude: !secret home_lat**
**  longitude: !secret home_long**
**  unit_system: metric**
**  time_zone: Europe/Madrid**
**  customize_glob:**
**    sensor.hidden*:**
**      hidden: true**
**    weather.vkshchi:**
**      hidden: true**
**# Configure a default setup of Home Assistant (frontend, api, etc)**
**default_config:**

**# Uncomment this if you are using SSL/TLS, running in Docker container, etc.**
**# http:**
**#   base_url: example.duckdns.org:8123**

**# Text to speech**
**tts:**
**  - platform: google_translate**

**# Include board specific configuration files**
**#######################################**
**# DAEnetIP4 (HTTP)**
**#######################################**
**group: !include DAEnetIP4.HTTP/groups.yaml**
**sensor: !include DAEnetIP4.HTTP/sensors.yaml**
**switch: !include DAEnetIP4.HTTP/switches.yaml**
**input_number: !include DAEnetIP4.HTTP/input_numbers.yaml**
**rest_command: !include DAEnetIP4.HTTP/rest_commands.yaml**
**scene: !include scenes.yaml**
**script: !include scripts.yaml**
**automation: !include automations.yaml**

Thanks again!

what is all this?

But assuming you have inserted all those ** characters in some bizarre copy/paste error, you have not included sensors.yaml

I guess ** is wrong use of Markdown (bold text)

The code snippet i gave you is intended to be directly in the configuration.yaml

That chars (**) dont appear in my file.
I’ve copy/paste from my file, and I don’t know why apear here…

As you can see, I have a line with “sensor: !include DAEnetIP4.HTTP/sensors.yaml”.

If I write any where “sensor: !include sensors.yaml” I get an error when I chek config in server control (obviously I dont delete the line “sensor: !include DAEnetIP4.HTTP/sensors.yaml”).

How can I write to include the file “/config/sensors.yaml”?

Thanks for your time! :slight_smile:

This is not in sensor part, this is in template part.
So, either you put this in configuration.yaml, either you create a template.yaml file and put :

  - sensor:
    - name: analog_input_1_numeric
      unit_of_measurement: 'mV'
      state: >
        {{ states('sensor.analog_input_1')[:-2]|int }}

in it and this into your configuration.yaml :
template: !include template.yaml

1 Like

is not DAEnetIP4.HTTP/sensors.yaml

I have no idea what this DAEnetIP4.HTTP/ garbage is in your file?

Great!!
I’ve chosen the first option you gave to me and works.

Thanks a lot!!

The line you say you don’t know refers to an external device with relays, AI and DI.
I need that line to use the sensors in that device. At least I think I need it…

Thanks!

Consider marking the solution on my post that helped you, it may help other homies :slight_smile:

Sorry!
I don’t have many experience in forums.

DONE! :grinning:

1 Like