Can someone help me?
I want to reset the rotary encoder value in ESPHOME when another entity has a vertain value.
Purpose is to set the rotary encoder value to 0 when an endstop, measured with reed relais on GPIO34 is shown with state “closed”.
I tried the presented method, but I receive the error “mapping values are not allowed here”
Here is the snipped of my yaml file:
Also I think you may have your values back to front and you possibly want to OR them rather than ANDing a range. Though I don’t know for sure:
on_value_range:
- above: 1.5 # reset above top end stop
then:
- sensor.rotary_encoder.set_value:
id: GS_Rotary_Encoder
value: 0
- below: 0.5 # or reset below bottom end stop
then:
- sensor.rotary_encoder.set_value:
id: GS_Rotary_Encoder
value: 0
The way you have it the encoder will reset if the value is between 0.5 and 1.5, not outside that range which is what the second version will do, reset if outside 0.5 to 1.5. However 0 is below 0.5 so that makes no sense.
If you want to confine it to the range 0.5 to 1.5 do this:
on_value_range:
- above: 1.5 # reset above top end stop
then:
- sensor.rotary_encoder.set_value:
id: GS_Rotary_Encoder
value: 1.5
- below: 0.5 # or reset below bottom end stop
then:
- sensor.rotary_encoder.set_value:
id: GS_Rotary_Encoder
value: 0.5
@tom_I
Many thanks for the fast reply.
Ideally I want to reset the rotary encoder when the binary input (GPIO) value changes from CLOSED to OPEN to avoid resetting in loop while in a certain value range.
I assume OPEN equals 0 and CLOSED equals 1 (?) or vice versa.
So in pseudo code:
if GPIO changes from 0 to 1 then rotaryencoder = 0
Oh right. Binary sensors do not have an “on value range” action.
That depends entirely on how you have connected it. As you have not inverted the input I’m going to assume Open is 1 (on / pressed) and Closed is 0 (off / released).
So you will have to do this. It triggers when the door opens and then checks the encoder value in a condition, if it passes the condition then the encoder is reset.
platform: gpio
pin: GPIO34
name: "GS Input DPIO34"
id: GS_Input_GPIO34
device_class: door
on_press: # change from logic 0 to 1, "on_release" is logic 1 to 0
then:
- if:
condition:
- sensor_in_range:
id: GS_Rotary_Encoder
above: 0.5
below: 1.5
then:
- sensor.rotary_encoder.set_value:
id: GS_Rotary_Encoder
value: 0
@tom_I
Many thanks. I can work with that - I understand now how to do this.
Actually you’ve posted a more complex solution than I needed …
So my solution simply looks like:
binary_sensor:
- platform: gpio
pin: GPIO34
name: "GS Input DPIO34"
id: GS_Input_GPIO34
device_class: door
on_release: # change from logic 1 to 0, "on_press" is 0 to 1
then:
- sensor.rotary_encoder.set_value:
id: GS_Rotary_Encoder
value: 0