Exploring Thermostat Automation with Input Helpers

Hi everyone, I’m diving into the world of thermostat automation and wanted to share my journey and some questions I have along the way. I recently set up an automation that adjusts the thermostat based on different modes like Eco, Comfort, and Spar mode. Here’s how I approached it:

I started by defining my thermostat modes in a JSON format, which looks something like this:

[
{
“mode”: “Eco”,
“temp”: 19.0
},
{
“mode”: “Comfort”,
“temp”: 20.0
},
{
“mode”: “Spar”,
“temp”: 17.0
},
{
“mode”: “Off”,
“temp”: 10
}
]

My goal was to loop through these modes and set the temperature based on the selected mode from an input select. Here’s the automation I came up with:

yaml

  • id: ‘123456789’
    alias: thermostat_modes_example
    variables:
    thermostat_modes: ‘[ { “mode”:“Eco”, “temp”:19.0 }, { “mode”:“Comfort”, “temp”: 20.0 }, { “mode”:“Spar”, “temp”:17.0 }, { “mode”:“Off”, “temp”:10} ]’
    trigger:
    • platform: state
      entity_id:
      • climate.radiator
        attribute: temperature
        condition:
        action:
    • service: input_number.set_value
      data_template:
      entity_id: input_number.temperature
      value: >-
      {% for thismode in thermostat_modes %}
      {% if thismode.mode == states(“input_select.thermostatmode”) %}
      {{ thismode.temp }}
      {% endif %}
      {% endfor %}

While this seems straightforward, I’m encountering some issues. For instance, the automation doesn’t always pick up the correct temperature based on the selected mode. I suspect it might be related to how the JSON data is being parsed or accessed within the template. Any insights or suggestions on how to troubleshoot this would be greatly appreciated!

I’m also curious if there’s a more efficient way to handle this kind of automation, especially if I want to add more modes or integrate additional sensors in the future. The community here has been so helpful, and I’m excited to learn more from everyone’s experiences!

Thanks in advance for your guidance and support! :raised_hands: