Automation of Scale Sensor trips over kg

I have a hx711 sensor that weighs my watersoftener and I try to run an automation that checks when the salt runs out by the weight going under 37kg.

The ESPHome sensor has a Unit of Measurement called “kg” but I can’t get the automation to work as the log complains that

(eg) hx711_value = 37kg and the “kg” is not a number.

I get that and the “state” of the hx711 seems to contain 37 without the “kg” but I don’t seem to be able to use that hx711.state in my automation.

What is the correct way to do this?

You need to share your sensor config and automation attempt.

How are you importing this into HA?
Can you post the sensor yaml and the automation yaml?
If the number and the units are always passed, it might be as simple as excluding the right two characters.

On a side note, I use an ultrasonic sensor to measure salt tank level and import it via MQTT to home assistant.

Salt Level

I am also starting work on a weight sensor for 3d printer filament.

Apologies for not sharing this before. Sensor code:

esphome:
  name: water_softener_weight
  platform: ESP8266
  board: d1_mini_pro

wifi:
  manual_ip:
    static_ip: 192.168.1.17
    gateway: 192.168.1.254
    subnet: 255.255.255.0

  networks:
    ssid: "hidden"
    password: "hidden"

deep_sleep:
  run_duration: 10s
  sleep_duration: 60min
  id: deep_sleep_1

sensor:
  - platform: hx711
    name: "HX711 Value"
    dout_pin: D1
    clk_pin: D2
    accuracy_decimals: 2
    gain: 128
    update_interval: 5s
    filters:
      - calibrate_linear:
          - 340500 -> 0
          - 363955 -> 1
    unit_of_measurement: kg

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

Automation:

id: '1609160142372'
alias: Email When Water Softener Empty
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.hx711_value
    above: '26'
    below: '37'
condition:
  - condition: template
    value_template: >-
      {{ (as_timestamp(now()) -
      as_timestamp(states.automation.email_when_water_softener_empty.last_triggered
      | default(0)) | int > 3600)}}
action:
  - service: notify.notifier_email_me
    data:
      message: Water Softener Empty
      title: Water Softener Empty
  - service: notify.mobile_app_me_iphone
    data:
      message: Water Softener Empty
      title: Water Softener
mode: single

Error:

Logger: homeassistant.components.homeassistant.triggers.numeric_state
Source: components/homeassistant/triggers/numeric_state.py:115
Integration: Home Assistant Core Integration (documentation, issues)
First occurred: 13:47:21 (1 occurrences)
Last logged: 13:47:21

Error initializing 'Email When Water Softener Empty' trigger: In 'numeric_state' condition: entity sensor.hx711_value state 'kg' cannot be processed as a number

Can you post what you have in developer tools for that sensor?

@GlennHA, is this what you mean:

hx711

Closed enough. So your sensor state does not contain ‘kg’, only the number 36.67.

Which makes that error very confusing.

Indeed - that’s what I thought. I’ll change my sensor today to take that Unit of Measurement out to see if that makes a difference unless someone has a different idea. Weird.

I was going to say something similar as @tom_l but I saw he was typing so I waited thinking he saw something I didn’t.
I don’t see anything obviously wrong.
For troubleshooting, remove the condition and the above trigger and see if it works.
Do you have a duplicate automation for this?
This ‘should’ not make a difference but you could also type “37.00”
I have had some weird instances if I have a number that changes state and hovers around the trigger value it has issues; so I always put a for: '00:00:10' at a minimum. I most circumstances 10 seconds won’t make any difference.
Make a duplicate automation, turn off the original, make changes to the copy one at a time and see what errors you get.

Tried all sorts and couldn’t get it to work. Moved to Node-Red instead which works perfectly