Temperature value cannot be processed as a number ( automation job) [SOLVED]

hi, hope i am in the right area,
I’m trying to configure my sonoff TH switch(using the latest local Sonoff LAN control from Home Assistant) to read the humidity level and switch a fan on accordingly.
with @peterbuga sonoff component it used to work like this
alias: Switch Bathroom Fan Off
description: Humidity drops below 55%
trigger:

below: ‘55’
entity_id: switch.sonoff_xxxxxxxx
platform: numeric_state
value_template: humidity
condition: []
action:
data:
entity_id: switch.sonoff_xxxxxxxx
entity_id: switch.sonoff_xxxxxxx
service: switch.turn_off

#but this needed the cloud to work,
the new version is local which is a major push, ( before people ask i’m not very confident in flashing tasmota)
i can get the swith working fine, no issues, and now can get HA reading the attributes and displaying them as sensors in the main lovelace AI setting up the sensors to display the following
“{{ state_attr(’‘switch.sonoff_10004b2680’’, ‘‘humidity’’) }}”

in re editing my automations i have tried to keep the automation as a numberic state

above: '60'
entity_id: sensor.humidity_purifier
platform: numeric_state
value_template: ''switch.sonoff_10004b2680'', ''humidity''

but looking in the logs i get

Value cannot be processed as a number: <state switch.sonoff_10004b2680=off; humidity=63, temperature=18, friendly_name=Bathroom Extractor Fan, supported_features=0 @ 2020-02-24T17:54:04.491675+00:00> (Offending entity: "63")

can anyone suggest how i use it then seeing as it says it cannot process the number even thouse the sensor on the main UI is displaying the humidity and temperature just fine?

i’m totally at a loss here.

i really appreciate any help, thank yoiu

you need to write your value_template as an actual template using the proper format:

value_template: "{{ state_attr('switch.sonoff_10004b2680', 'humidity') }}"
1 Like

Thanks for the reply

- id: '1574230040095'
  alias: Switch Bathroom Fan On
  description: switch on fan when humidity is above 60%
  trigger:
  - above: '60'
    entity_id: sensor.humidity_purifier
    platform: numeric_state
    value_template: '"{{ state_attr(''switch.sonoff_10004b2680'', ''humidity'') }}"'
  condition: []
  action:
  - data:
      entity_id: switch.sonoff_10004b2680
    service: switch.turn_on

the additional ’ around he value template is added automatically by HA
i have tried both with and without them and it doesn’t seem to be working, there’s no error’s in the log, do you know how i can troubleshoot it more?

Are you trying to trigger off of the “sensor.humidity_purifier” state going above 60 or the “humidity” attribute of the “switch.sonoff_10004b2680” going above 60?

i have the sonoff th16 switch, i’m trying to read the humidity level from the sensor and if it goes above 60% then trigger the sonoff switch, if it drops below 60 then to turn the switch off.,

just as reference this is how i got the temperatures to be read in HA

sensor:
- platform: template
  sensors:
    temperature_purifier:
      friendly_name: WetRoom Temperature
      device_class: temperature
      value_template: "{{ state_attr('switch.sonoff_10004b2680', 'temperature') }}"
    humidity_purifier:
      friendly_name: WetRoom Humidity
      device_class: humidity
      value_template: "{{ state_attr('switch.sonoff_10004b2680', 'humidity') }}"

you’ll have to help me out a bit here. I don’t have a Sonoff TH16.

How are the “sensor.humidity_purifier” and “switch.sonoff_10004b2680” related?

is the humidity sensor inside the Sonoff TH16 and is that value an attribute of the Sonoff TH16?

if that is the case then where does the “sensor.humidity_purifier” fit in?

Looking in the states table for the sonoff switch

Entity = switch.sonoff_10004b2680
state = off
filter attributes = Humidity: 73  Temperature 18 friendly_name: Bathroom Extractor Fan Supported features: 0

https://github.com/AlexxIT/SonoffLAN is the component

try this for the turn on part:

- id: '1574230040095'
  alias: Switch Bathroom Fan On
  description: switch on fan when humidity is above 60%
  trigger:
  - above: '60'
    entity_id: switch.sonoff_10004b2680
    platform: numeric_state
    value_template: "{{ state.attributes.humidity }}"
  condition: []
  action:
  - data:
      entity_id: switch.sonoff_10004b2680
    service: switch.turn_on

i really appreciate this assistance thank you
both set to the below and still no joy, if there a debug level i can set to see what’s going on in the background maybe?

- id: '1574230040095'
  alias: Switch Bathroom Fan On
  description: switch on fan when humidity is above 60%
  trigger:
  - above: '60'
    entity_id: switch.sonoff_10004b2680
    platform: numeric_state
    value_template: "{{ state.attributes.humidity }}"
  condition: []
  action:
  - data:
      entity_id: switch.sonoff_10004b2680
    service: switch.turn_on
- id: '1574230212471'
  alias: Switch Bathroom Fan Off
  description: Humidity drops below 60%
  trigger:
  - below: '60'
    entity_id: switch.sonoff_10004b2680
    platform: numeric_state
    value_template: "{{ state.attributes.humidity }}"
  condition: []
  action:
  - data:
      entity_id: switch.sonoff_10004b2680
    service: switch.turn_off

any thoughts anyone?

try this as your trigger in the turn on automation:

trigger:
  - platform: template
    value_template: "{{ state_attr('switch.sonoff_10004b2680', 'humidity') | int > 60 }}"

boom, thank you, that is working now

Hi, I’m trying to do the same thing but with the temp and for some reason I can’t get it to work for the life of me.


Take a look at this marked up image

Now, does your sensor.living_room_sensor_temperature have a temperature attribute?

Or

Should you be getting the state from sensor.living_room_sensor_temperature?

Guessing I should change it to state? Is all I have to do is remove the “_attr”? or is there more to it like this?


More info if it helps

Very close, I’m on mobile so i can’t type the whole thing out. The only error I see is that you’re using state( when it should be states(.

I did as suggested and changed it to “states” and it still doesn’t trigger. I tested the action manually and it works to turn on the relay but the trigger logic won’t work. I found a different post and they were adding logic to trim the value to a whole number instead of the “72.00” it would be “72” but when I tried that it didn’t work ether. It’s got to be something simple but I just can’t seem to figure out what.

It’ll only trigger when it changes from above 80 to less than 80. If it’s already below 80 it will not trigger if it moves further below 80 or to another number that’s less than 80z

Ok, that makes sense. How can I change the automation to work if the temperature state is already below 80?