Restore input_select value from MQTT topic?

Hello all,

I was wondering if anyone was using a input_select to switch between options while updating a MQTT topic on “state_changed” and then restoring previously selected option?

I have the automation to publish the change but I’m scratching my head trying to figure out how to restore the current input_select on homeassistant_start.

Basically, I have some automation setup to switch between different modes throughout the day and the transition has one of many conditions on the previously selected mode. If I restart HA, then I lose the previously selected mode and it defaults to initial. This is one huge learning exercise for me and I appreciate any help given.

I apologize if this is documented somewhere, I haven’t found it yet.

This thread might be of help. Let me know if it works out for you.

Interesting… Thank you, I have not seen this. I’m guessing this isn’t possible to do then natively then?

Thanks, I’ll check it out tomorrow!

I do this with my own version of thermostat control with an automation rule like this and ensuring the mqtt topic is set to retain so it gets the last known value on start.

- alias: "Keep Thermostat Input Select Updated"
  trigger:
    platform: mqtt
    topic: house/thermostat/setpoint
  action:
    service: input_select.select_option
    entity_id: input_select.thermostat_set
    data_template:
        option: '{{states("sensor.thermostat_setpoint")|round(0)}}'

I then use a rule like this to pass new values back to the mqtt topic:

- alias: "Pass new thermostat setpoint out to MQTT"
  trigger:
    platform: state
    entity_id: input_select.thermostat_set
  action:
    service: "mqtt.publish"
    data_template:
        topic: "house/thermostat/setpoint"
        retain: "false"
        payload: '{{states("input_select.thermostat_set")}}'
2 Likes

Brilliant, I believe this is the second half of what I was looking for… Thank you!

This worked perfectly for what I was trying to do. Thanks again.