Automation, numeric state does not have the correct attribute imho

Hi,
I have an entity/sensor included into HA from an http rest api. More or less I have a number which i receive.
I can show these numbers correctly in the dashboard but when I try to run automations against the value of the entity I got stuck.

My first try was to choose the entity and use numeric state to set below/above values. But I can only choose the following attributes

  • Unit of measurements
  • Device Class
  • Friendly Name

but not the value itself. Which would be the most obvious one in my opinion. What am I doing wrong? Thanks in advance
Thomas

Automation Trigger - Home Assistant (home-assistant.io)

When the attribute option is specified the trigger is compared to the given attribute instead of the state of the entity.

So leave it blank if you want the state

Maybe I said it a bit confused. I have a moisture sensor. Which has a value between 0 and 100. Integer to be exact. In my yaml config I have unit of measurement defined with a “%”. And I want to check for example do something if the value is below 40.
And that is not working afaik. Any suggestions?

Since we don’t see what you are doing all we can do is go by what you are saying.
And what you said was incorrect. Do not use the attribute field.
If you want more help then this the paste your code here.

1 Like

This has arisen a few times before: people mistakenly think they must select an attribute, and then ask why their automation doesn’t work, because it’s looking for a change in the unit_of_measurement, for example.

@TommyMyName — just leave the attribute field empty, and then the automation will use the sensor state (which is a separate thing: think of it as the “primary attribute” if you like, and the others as “secondary”).

This bit of the UI could perhaps be tweaked to try to avoid the tendency of newbies to incorrectly populate the Attribute field.

Reduced the code to a minimum.

sensor:
  - platform: rest
    name: raised_bed
    resource: http://x.x.x.x:5000/raised_bed
    json_attributes:
      - "RB_A_1_moisture"
      - "timestamp"
  - platform: template
    sensors:
      raised_bed_rb_a_1_moisture:
        value_template: '{{ states.sensor.raised_bed.attributes["RB_A_1_moisture"] }}'
        device_class: humidity
        unit_of_measurement: "%"

So my question is, I can see the number correctly in the dashboard and how can I create automations based on that value?

alias: New Automation
description: ''
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.raised_bed_rb_a_1_moisture
    below: '40'
condition: []
action: []

As Troon and Hellis said, leave the attribute blank. You don’t need it. Attribute is for any sub attributes on an entity. You want the state, which is just the entity itself. Therefor you leave attribute blank.

If I let the attribute empty and click on test I get an error.

whats the error…

This is really cute and all that.
But as I said previously POST THE CODE IF YOU WANT HELP, not images of parts of the GUI

My yml looks like this. This is the yml from the screenshot above.

condition: numeric_state
entity_id: sensor.raised_bed_rb_a_1_moisture
below: '40'

Posting UI images is fine. I’ll help him if you don’t want to.

Yes, I’d like to see the error though. Thanks

I can post all the code if you want to dive through everything Hellis. After that i also WANT A QUALIFIED ANSWER, to speak in your words.

Which source code do you need Hellis?

let me check the logs petro

My first thought was that I am doing something wrong in the gui that the most obvious thing to check the value is not working for me.

Log stays empty if I keep attribute empty. If I for example choose an attribute I see the error log from my first post.

Post the code of this automation. Yes. post it all not just parts of it.

- id: '1628710151606'
  alias: bathtub_pump_uv_desinfect_power_on_at_02:00
  description: ''
  trigger:
  - platform: time
    at: 02:00
  condition: []
  action:
  - type: turn_on
    device_id: f5cf508eb18d2a3d967d5e22a4846efb
    entity_id: switch.node_4
    domain: switch
  - type: turn_on
    device_id: 42eb63352a750d8959c999c46dbdc2a8
    entity_id: switch.node_8
    domain: switch
  mode: single
- id: '1628710378374'
  alias: bathtub_pump_uv_desinfect_power_off_at_10:00
  description: ''
  trigger:
  - platform: time
    at: '10:00'
  condition: []
  action:
  - type: turn_off
    device_id: f5cf508eb18d2a3d967d5e22a4846efb
    entity_id: switch.node_4
    domain: switch
  - type: turn_off
    device_id: 42eb63352a750d8959c999c46dbdc2a8
    entity_id: switch.node_8
    domain: switch
  mode: single
- id: '1629214765069'
  alias: Low battery level detection & notification for all battery sensors
  description: ''
  use_blueprint:
    path: sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
    input:
      threshold: 20
      actions:
      - device_id: 08c642c5ec9b5702181483445ada15fb
        domain: mobile_app
        type: notify
        title: 'Low battery warning for: {{sensors}}'
        message: 'Low battery warning for: {{sensors}}'
      time: '10:00:00'
- id: '1650212337093'
  alias: start_irrigation_rb_a
  description: ''
  trigger:
  - platform: time
    at: 06:05:00
  - platform: time
    at: '18:05:30'
  condition:
  - condition: numeric_state
    entity_id: sensor.raised_bed_rb_a_1_moisture
    attribute: friendly_name
    below: '40'
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.relay_rb_a
  mode: single