Number being treated as text

Hi everyone, I’ve got a scrape sensor setup that retrieves a decimal number from a website.

Unfortunately, the returned number is being treated as text, so I can’t view its history as a graph or use Numerical State triggers for automations.

I’ve tried to use this option to force a conversion to a number:
value_template: '{{ value | float }}'

But doesn’t seem to work. Adding a unit doesn’t seem to have worked either.

Suggestions would be awesome!

EDIT: corrected value_template

Would be easier if you posted the whole sensor yaml to see how you’ve done it, but I think you’ll need to use value_template: '{{ value | float }} instead of data_template:

1 Like

Oh sorry! Yes, I was using value_template, this is why I should’ve posted it to avoid the mixup. Here’s the config:

  - platform: scrape
    name: Metro 14-Day Average
    select: ".info.DAYS-AVERAGE-METRO-VIC p"
    value_template: '{{ value | float }}'
    scan_interval: 1800

I should also mention that the numbers are currently being used for a gauge card on my frontend. The card has been interpreting the value as a number without any issues.

Add a unit_of_measurement to enable graphing numeric values.

1 Like

I did try this out to see if it would work, it seems not to have helped.

In other situations, I’ve seen that input_number entities work properly too without units of measurement.

For the record, each time I made a change I used a SQLite command to clear out state history, then a restart.

Please post your new config with the unit added. Also you may have to refresh your browser cache and wait 24 hours for the previous measurements to disappear (usually results in dual graphs for 24 hours / graphing period).

So at the moment the config is currently:

  - platform: scrape
    name: Metro 14-Day Average
    select: ".info.DAYS-AVERAGE-METRO-VIC p"
    value_template: '{{ value | float }}'
    unit_of_measurement: "Cases"
    scan_interval: 1800

I’m clearing the DB of states related to this entity before each restart.

You have two units. Delete one.

Thanks! Excuse my copy-paste fail

Alright, adding a unit of measurement seems to have worked. I’ve silenced the unit in the gauge by using a blank space for the unit.

Thanks for suggestions!

Hi, I will continue this thread cause I have a similar problem, and I’m going nuts.
I get the forecasted temperature for tomorrow, this kind of works I can se the values on my dashboard.
I then try to make an automation that has a condition if forecasttemp0 is below 10 then do the action
( now the action is only a number increment)
But the problem is that the - condition: numeric_state doe not work with my temperature value.
Ive tried to read these topics, tried to add a float and a int , tried to add unit of measurement. The automation UI somethings creat an extra value_template: “” line, but removing it does not help either.

Then What, I know it’s some stupid misstake I made, but I need help :slight_smile:

Below is some info.

The Error code is:
Executed: November 15, 2022 at 23:27:59

result: null

## conditions/0

Executed: November 15, 2022 at 23:27:59

Error: In ‘numeric_state’: In ‘numeric_state’ condition: entity sensor.forcasttemp0 state ‘’ cannot be processed as a number

## conditions/0/entity_id/0

Executed: November 15, 2022 at 23:27:59

Error: In ‘numeric_state’ condition: entity sensor.forcasttemp0 state ‘’ cannot be processed as a number

My configuration.yaml, weather.forecast_lasilaakso

  • platform: template
    friendly_name: “tempnow”
    value_template: “{{ state_attr(‘weather.forecast_lasilaakso’, ‘temperature’) }}”
    friendly_name: “forcasttemp0”
    value_template: “{{ (state_attr(‘weather.forecast_lasilaakso’, ‘forecast’)[0].temperature | int)}}”
    unit_of_measurement: “c”
    friendly_name: “forcasttemp1”
    value_template: “{{ state_attr(‘weather.forecast_lasilaakso’, ‘forecast’)[1].temperature }}”

My automation:
alias: test 19 on
description: “”

  • platform: time
    at: “11:00:00”
    condition: []
  • choose:
    • conditions:
      • condition: numeric_state
        entity_id: sensor.forcasttemp0
        below: 10
        value_template: “”
      • service: input_number.increment
        data: {}
        entity_id: input_number.heatinggroupnr
        mode: single