Bidirectional input_slider

My scenario:
I have a fan and I control it’s speed using an input_slider and an automation. I have a sensor that reads the fan speed, and when it changes am automation is triggered to change the value of the input slider.

My issues

  1. When HA is restarted the default value of the input_slider triggers an event and thus might trigger the automation to write the default value to the input_slider to the fan.
  2. When the fan speed is changed on the fan instead of the input_slider the fan speed sensor will trigger the automation to update the input_slider value and the change of the input_slider will trigger an event to write the same value back to the fan.

I don’t really know how to solve this. My first idea was to let an input_slider have a “disabled” property, and with an automation make it enabled when the first value was received from the fan_sensor.

For the second issue I guess it would be possible to see in the automation who triggered the change on the input_slider, if it was the UI or an automation. If it was the sensor the automation can ignore the event and don’t write the value back to the fan.

Does anyone have any input or better ideas? I really don’t want to make any changes that increases the complexity too much.

Your automation is triggered by a “change”. Well, at bootup, the slider is at a default value of zero, I believe, so it should not trigger a “change” event and therefore should not trigger the automation, but then again, I don’t know your HA setup, so I don’t know what is happening at startup and what automations you have triggering and when.

As for changing the speed on the fan manually, both of your automations should be checking that the new value does not already match the other value, so if they match, don’t change the slider or update the fan, and if they don’t match, then you can send the change.

Basically, as long as you are verifying the values before performing the action, then you should never get caught into that loop.

alias: 'If fan speed changes, update fan slider'
trigger:
  platform: state
  entity_id: sensor.fan_speed
condition:
  condition: template
  value_template: '{{ states.sensor.fan_speed.state != states.input_slider.fan_speed.state }}'
action:
  service: input_slider.select_value
  data_template:
    entity_id: input_slider.fan_speed
    value: '{{ trigger.to_state.state }}'

And since I don’t how you are communicating with your fan via the slider, I can only give an example using something like MQTT to do the same verification on the other side:

alias: 'If fan slider changes update fan speed'
trigger:
  platform: state
  entity_id: input_slider.fan_speed
condition:
  condition: template
  value_template: '{{ states.input_slider.fan_speed.state != states.sensor.fan_speed.state }}'
action:
  service: mqtt.publish
  data_template:
    topic: 'homeassistant/fan/speed'
    payload: '{{ trigger.to_state.state }}'
    retain: true
1 Like

Thank you!

The first issue was caused by my automation. I was accidentally setting the slider to it’s old value instead of the new value from the sensor. So when the first sensor value arrived I wrote the initial slider value to the device.

The other issue can as you say be prevented with a condition. I never had a loop, I just thought it was an unnecessary call to the device.

I will still write the current value back to the device once when I start HA since the initial value of the input_slider might differ from the first value reported from the sensor. But that is OK really, won’t do any harm.

Did you get this figured out?

If so, can you share your lines that are setting the slider with an incoming value?

thanks

Here is an example where I set the slider value:

automation:
  - alias: Set fan speed slider value
    trigger:
      platform: state
      entity_id: sensor.fan_speed
    action:
      service: input_slider.select_value
      data_template:
        entity_id: input_slider.fan_speed
        value: '{{ states.sensor.fan_speed.state }}'

If you want to see it all, have a look at: https://github.com/persandstrom/.homeassistant/blob/master/configuration.yaml

2 Likes

that worked.
thanks.

that example would make a good a addition to the components page

Why don’t you make the change? https://github.com/home-assistant/home-assistant.github.io/blob/current/source/_components/input_slider.markdown

Does Input Number support the “select_value” service shown above? I tried the following action and it doesn’t work:

    action:
      service: input_number.select_value
      data_template:
        entity_id: input_number.shop_heater_scheduled_temp
        value: '{{ 70 }}'

I get the following warning in the log:

WARNING (MainThread) [homeassistant.core] Unable to find service input_number/select_value

It was in the documentation.

service: input_number.set_value