Esphome automation help re: on_value_range

Hello again all,

I have found esphome and have built some great sensors and updated a few of my tasmota devices as well.

Going good with the basic coding but just cant get my head around the automations, i have been working on building the sensor as stated in the esphome automations sensor https://esphome.io/guides/automations.html .
I have the humidity sensor working with a value range as per the above site address eg.

on_value range

- platform: dht
  humidity:
	name: "Living Room Humidity"
	on_value_range:
	  - above: 65.0
	      then:
	        - switch.turn_on: dehumidifier1
	  - below: 50.0
	      then:
	        - switch.turn_off: dehumidifier1
	temperature:
      name: "Living Room Temperature"

What im trying to do is set the above and below values to a home assistant sensor
that can adjust the humidity level with an input_slider`
Untitled%20picture

Ive
built the slider on my home assistant and have the values showing on the
esphome web server interface,
Untitled%20picture

Just stuck with getting this value into
esphome.yaml. Below is what im looking to do

humidity:
  name: "Humidity"
on_value_range:
  - above: 65.0  { i want this to be the home assistant sensor with id "humidity_set"}
      then:
        - switch.turn_on: dehumid_switch
  - below: 50.0  { i want this to be the home assistant sensor with id "humidity_set"}
      then:
        - switch.turn_off: dehumid_switch
update_interval: 10s

OR

If humidity rises above my slider value then turn on my dehumidifier, and when the humidity drops below my slider value then turn off my dehumidifier

Please any help would be very greatful, and thankyou in advance

Heres my yaml.

esphome:
  name: esp32controller
  platform: ESP32
  board: nodemcu-32s  

wifi:
  ssid: "CRGSECRET"
  password: "yeahright"


logger:

api:

text_sensor:
  - platform: wifi_info
    ip_address:
      name: ESP IP Address
    ssid:
      name: ESP Connected SSID
    bssid:
      name: ESP Connected BSSID

ota:

web_server:
  port: 80

switch:
  - platform: gpio
    name: "Ceiling Fan"
    pin: GPIO17
    inverted: yes
    id: ceiling_fan_switch  
  - platform: gpio
    name: "Dehumidifier outlet"
    pin: GPIO16
    inverted: yes
    id: dehumid_switch  
 
    
    
sensor:
  - platform: dht
    pin: GPIO23
    model: DHT11
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
	  on_value_range:
        - above: 65.0
          then:
            - switch.turn_on: dehumid_switch
        - below: 50.0
          then:
            - switch.turn_off: dehumid_switch
    update_interval: 10s
       

  - platform: homeassistant
    name: "Temp Set Point"
    entity_id: input_number.desired_temperature
    id: temperature_set
  - platform: homeassistant
    name: "Humidity Set Point"
    entity_id: input_number.desired_humidity
    id: humidity_set
1 Like

Why not do all the automation in home assistant?

want it obsolete from any server only ha control will be the slider value, plus version 2.0 will use a rotary encoder to set humidity,

im making IOT Device with my ESP-32 and would like it to function as a stand alone device as i believe its best for HA failure or any other reason to add a dial or switch that connects directly to HA but can also work in conditions by itsself, just sounds logical to make the device communicate with itself first before needing to send data to my HA Setup

There are arguments both ways - ideally home assistant should know everything and all automations should be done there. Then everything is centralised.

Not really helping my issue nickrout.

so whats tour way of doing this then could you provide me with some automations in HA as well as anyone else with some proactive advice would be appreciated

I have been just refreshing my memory of the esphome docs so I could help you. I think you want this to import a value set by a home-assistant entity. https://esphome.io/components/sensor/homeassistant.html

So to rephrase my question

im making IOT Device with my ESP-32 that i would like to get sensor value from my ha to perform a basic automation to turn a relay on all values will be provided to and from both HA and my Iot device. need help with some basic coding please see my first post any help with coding my espyaml

im getting this value already from HA but thanks for the input

Unti11tled

Untitled

Is it working?

I think that you might need a lambda, just looking at this example: https://esphome.io/guides/automations.html#templates-lambdas

just working on that now

sensor:
  - platform: dht
    pin: GPIO23
    model: DHT11
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
      on_value:
        then:
	  - if:
	      condition:
	        lambda: 'return id(sensor.humid).state > return id(humidity_set);'
	then:
	   - logger.log: "The Dehumidifier has switched on!"
	   - switch.turn_on: dehumid_switch
           - delay: 2s
	else:
	   - logger.log: "The Dehumidifier has reached the Setpoint!"
	   - light.turn_off: dehumid_switch

oops ill edit that text

still no good i have updated to reflect my changes but no success yet

newest code

sensor:
  - platform: dht
    pin: GPIO23
    model: DHT11
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
      id: sensor.humid
    on_...:
      then:
        - if:
            condition:
              lambda: 'return id(sensor.humid).state > return id(humidity_set);'
                then:
                  - logger.log: "The Dehumidifier has switched on!"
                  - switch.turn_on: dehumid_switch
                  - delay: 2s
      else:
        - logger.log: "The Dehumidifier has reached the Setpoint!"
        - switch.turn_off: dehumid_switch   
    update_interval: 10s

My first guess would be your formating is wrong. look at the example:

> on_...:
>   then:
>     - if:
>         condition:
>           lambda: 'return id(some_sensor).state < 30;'
>         then:
>           - logger.log: "The sensor value is below 30!"
>           - light.turn_on: my_light
>           - delay: 5s
>         else:
>           - logger.log: "The sensor value is above 30!"
>     - light.turn_off: my_light

Further include the on_…: should probably be on_value:

ill have another look thanks for the help

to date

#    
  - platform: dht
    pin: GPIO23
    model: DHT11
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
      id: sensor_humid
      on_value:
      then:
        - if:
            condition:
              lambda: return id(sensor_humid).state > id(humidity_set.state);
            then:
              - logger.log: "The Dehumidifier has switched on!"
              - switch.turn_on: dehumid_switch
              - delay: 2s
            else:
              - logger.log: "The Dehumidifier is under the Setpoint. Now off!"
              - switch.turn_off: dehumid_switch   
    update_interval: 10s

ok solved here is the way i did it

sensor:    
  - platform: dht
    pin: GPIO23
    model: DHT11
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
      id: sensor_humid
      on_value:
        then:
          - if:
              condition:
                lambda: 'return id(sensor_humid).state > id(humidity_set).state;'
              then:
                - logger.log: "The Dehumidifier has switched on!"
                - switch.turn_on: dehumidifier_switch
                - delay: 2s
              else:
                - logger.log: "The Dehumidifier is under the Setpoint. Now off!"
                - switch.turn_off: dehumidifier_switch   
    update_interval: 10s
2 Likes

Full yaml ( my bad)

esphome:
  name: esp32controller
  platform: ESP32
  board: nodemcu-32s  

wifi:
  ssid: "CRGSECRET"
  password: "yeahright"


logger:

api:

text_sensor:
  - platform: wifi_info
    ip_address:
      name: ESP IP Address
    ssid:
      name: ESP Connected SSID
    bssid:
      name: ESP Connected BSSID

ota:

web_server:
  port: 80

switch:
  - platform: gpio
    name: "Ceiling Fan"
    pin: GPIO17
    inverted: yes
    id: ceiling_fan_switch  
  - platform: gpio
    name: "Dehumidifier outlet"
    pin: GPIO16
    inverted: yes
    id: dehumid_switch  
 
    
    
sensor:    
  - platform: dht
    pin: GPIO23
    model: DHT11
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
      id: sensor_humid
      on_value:
        then:
          - if:
              condition:
                lambda: 'return id(sensor_humid).state > id(humidity_set).state;'
              then:
                - logger.log: "The Dehumidifier has switched on!"
                - switch.turn_on: dehumidifier_switch
                - delay: 2s
              else:
                - logger.log: "The Dehumidifier is under the Setpoint. Now off!"
                - switch.turn_off: dehumidifier_switch   
    update_interval: 10s
       

  - platform: homeassistant
    name: "Temp Set Point"
    entity_id: input_number.desired_temperature
    id: temperature_set
  - platform: homeassistant
    name: "Humidity Set Point"
    entity_id: input_number.desired_humidity
    id: humidity_set
1 Like

Hi, could you help me? I would like to add to my cover in esphome a slider that marks the position of the curtain. My code is currently:

binary_sensor:

- platform: gpio
  pin:
    number: GPIO02
    mode: INPUT_PULLUP
    inverted: True
  id: ph_button3
  on_press:
  - cover.open: my_cover
  on_release:
  - cover.stop: my_cover
  
- platform: gpio
  pin: 
    number: GPIO03
    mode: INPUT_PULLUP
    inverted: True
  id: ph_button4
  on_press:
  - cover.close: my_cover
  on_release:
  - cover.stop: my_cover

switch:
- platform: gpio
  pin: GPIO04
  interlock: &interlock [open_cover, close_cover]
  id: open_cover
- platform: gpio
  pin: GPIO05
  interlock: *interlock
  id: close_cover

      
cover:

- platform: time_based
  name: "myroom_window"
  id: my_cover
  open_action:
    - switch.turn_on: open_cover
  open_duration: 4s

  close_action:
    - switch.turn_on: close_cover
  close_duration: 4s

  stop_action:
    - switch.turn_off: open_cover
    - switch.turn_off: close_cover

what do I have to add to see also the position slider besides the forward, back and stop buttons?
Thank you!!!