Issue with automation with numeric state

Trying to get home assistant to switch on lights when it’s cloudy (> 60%). This is my code . Any suggestions?

- alias: "Turn on cloudiness scen when >60 % and someone home"
    trigger:
      platform: numeric_state
      entity_id: sensor.yr_cloudiness
      value_template: '{{ state.attributes.battery }}'
      above: 60
    condition:
      condition: state
      entity_id: device_tracker.androidce4eef065a60770clan
      state: home
    action:
      service: scene.turn_on
      entity_id: scene.slck_alla_lampor

Why are you using the value_template? Try removing that line and test if that triggers the automation.

Solved unfortunately not the problem. Wrote code like this

-alias: "Turn on cloudiness scen when >60 % and someone home"
        trigger:
          platform: numeric_state
          above: 60
          entity_id: sensor.yr_cloudiness
        condition:
          condition: state
          entity_id: device_tracker.androidce4eef065a60770clan
          state: home
        action:
          service: scene.turn_on
          entity_id: scene.slck_alla_lampor

Yeah, you could have used the above example if you called the right value in the template instead of state.attributes.battery though.

It would be nice to combine the yr_cloudiness and the sun elevation to turn on lights when it is getting dark. Any ideas of a smart way of doing so?

What shall i wirite insted off state.attributes.battery on the Line templates. Can’t get it work? I will use sensor.yr_cloudiness

That should be correct.

For some reason the following automation does never trigger (the sensor updates correctly):

- alias: 'Phone battery low'
  trigger:
    platform: numeric_state
    entity_id: sensor.battery
    below: 25
  condition:
    condition: state
    entity_id: device_tracker.xxxxxx
    state: 'home'
  action:
    service: tts.google_say
    entity_id: media_player.home_group
    data_template:
      message: 'Your smartphone battery is at {{  states.sensor.battery.state }} percent. Dont forget to charge your phone.'

Any idea what’s wrong?

  trigger:
    platform: numeric_state
    below: '25'
    entity_id: sensor.battery
    value_template: '{{  states.sensor.battery.state  }}'

Also doesn’t work.

Also tried this:

    below: 25

Same issue here with temperature values like 50.5

trigger:
  platform: numeric_state
  entity_id: sensor.temperature
  #value_template: '{{ state.sensor.temperature }}'
  above: 40

I’ve tried with and without the value_template, above as “40” and “40.0”, nothing works.

Any hints?

Hi,

has anyone gotten this to work? I also wanted to try an automation using numeric_state, but it’s not triggering.
I want to turn on some lights when it’s getting dark. Instead of using a sunset trigger with an offset, I decided to use a luminance sensor:

alias: 'Turn On Movie Lights After Sunset'
trigger:
  - platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_17_3
    below: 3.0
    value_template: '{{ state.state }}'
condition:
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_17_3
        value_template: '{{ state.state }}'
        below: 3.0
      - condition: or
        conditions:
        [...]

There’s another trigger and some more conditions in the or-Part, but those worked reliably so far when I used a sunset trigger/condition.
I just replaced the latter with the numeric_state trigger/condition and it hasn’t worked since.

I’m not even sure if I’d need the value_template since the value I want to trigger on is the sensor’s state and not one of the attributes.
Unfortunately the documentation does not state if this is optional or not.
The numeric_state condition example in the docs uses states.state and I’m guessing that this is expanded to states.<entity_id>.state - however, my lights stay dark.
I also already tried without the value_template line, but with the same result.

Can anyone enlighten me how to use this correctly?

Sebastian

Upgraded to 0.41 today and now my automation worked! :slight_smile:

Sebastian