Another simple automation question

Hello-

I know you guys have answered a ton of questions like this, and I have studied these threads, and attempted this for a while to the point where I know I am missing something crucial.

I have an esp8266 reporting DHT22 readings via mqtt, and everything is working as it should- I get sensor values in the UI. The switch works too- it is a WEMO switch. I would like to set up a simple automation whereby a switch is turned on if sensor values are above a given range. Should I be using the mqtt platform, or is the numeric_state platform better suited for this purpose? From what I can tell, the mqtt platform works by matching the payload string, which could work but the the numeric_state platform is what I am attempting here. So far, I have not gotten this automation to work. The 62.00 value in the .yaml matches the decimal place values of the sensor output.

Do I need to use a value template to extract data from payload?

value_template: '{{ value_json.temperature }}'

Do I need a condition?

Thank you,

-Rev

UI screenshot: https://www.dropbox.com/s/sywuyq1x5bcoaod/Screenshot%202017-05-24%2010.48.44.png?dl=0

relevant .yaml snippet

automation:
  trigger:
    platform: numeric_state
    entity_id: sensor.humidity
    above: 62.00

  action:
    service: switch.turn_on
    entity_id: switch.test

What you have is good, and should work without any condition.

Interesting. So, I can use

platform: numeric_state

with mqtt? So I don’t need anything like like automation templating: https://home-assistant.io/docs/automation/templating/

I am really stuck here, and have no idea why this isn’t working. Every component involved work fine in isolation. The whole point of setting all this stuff up was to get in to automation, and I feel like I am close…

I use …

- platform: mqtt
  state_topic: 'stat/NodeMCU_Sensors/temp'
  name: 'Pressure Sensor Temp'
  unit_of_measurement: '°C'
  value_template: '{{ value_json.Temp }}'

and the above creates a sensor in HA called…

sensor.pressure_sensor_temp

which you can then use in your automation

Ok. That is not in your automation, but rather a sensor component, correct?

Interestingly enough, its working now. I’ll post back here if I figure out why.

I am curious though if there is a way to do this on a platform other than

numeric_state

It’s mqtt formatted sensor code/json code and will work with any hardware that outputs the correct json code { “Temp”: 26, “Humidty”: 45 } to the correct topic for your hardware. Yep it goes in my sensor.yaml file. you can probably use a template to get the data but I find it easier to use the above code.

yes, of course :wink: no my question was regarding the way(s) to set up the automation with this type of sensor, i.e. do you use the numeric state or some other way. I have since gotten it to work, but I am wondering if there are other methods using the value_template. I think I should do more reading… https://home-assistant.io/components/sensor.mqtt/

You basically have to use a platform that’s applicable to the data type you are trying to trigger off of, for instance I have a sleep mode trigger via mqtt which only uses the payload of yes/no, but if you have to extract a value for an automation then I use the above…

 - alias: 'Sleeping'
   trigger:
     - platform: mqtt
       topic: stat/sleeping
       payload: 'yes'

It may not be the optimal but it works for me :slight_smile:

1 Like

So, in this instance

you would use numeric_state?

Yep since it’s a numeric answer that’s required for any automations that you may need to calculate a trigger for, if that makes sense :slight_smile: