Thermostat rule

Hello,
I would like to create a rule with an ESP32 relay turning on the gas heater when the current temperature is lover then the setpoint. When the setpoint and the current temperatur is equel then turn it off. I tried to use some rules from the net but none of them working for me.

Here is the relay that i would like to use:

The 2 temperature item is here with yellow background :

The termosztát is the set temperature item, the other is the current.
Thanks for the reply!

Please show what rule you tried? Are you using DSL, Script or Blockly?

I would recommend to use Blockly - this example should exemplify this:

make sure you add the trigger of the temperatur to the rule.

Hope that helps.

When showing your configs, please open the item’s page, click the code tab and paste the YAML you find there using code fences. The screen shots are hard to read, can not be searched, can not be copied and edited with corrections, and leave a lot of context out.

With the screen shots you’ve shown we know next to nothing about these Items beyond their names and types.

Use code fences

```
code goes here
```

And definitely post what you’ve tried because that gives us the best insight into your ultimate goals as well as what might be causing you problems.

Now to your question. @stefan.hoehn has posted a good start and the over all approach but I recommend you modify your requirements a little bit.

What if the temp jumps above the setpoint between readings? The heat will remain ON. You can fix that by changing the requirements to greater or equal.

But what if the temperature is bouncing just a little above and a little below the setpoint? The heater will be constantly turning on and off. This is usually inefficient and could be damaging to some hardware.

Instead often what some use in this sort of case is hysteresis. For example, turn OFF the heater when the setpoint is reached or exceeded but don’t turn it ON until the temperature has dropped a certain amount below the setpoint (e.g. 2 degrees). That gives a buffer to prevent the relay from flapping on and off when the temp is bouncing around the setpoint.

And for this, you are in luck as there is a profile that solves exactly this problem without rules. You can link the Channel supplying the temperature reading to a Switch Item and set the Hysteresis profile on the link. That profile will turn the switch ON at your setpoint and off when it’s a little below the setpoint. However, with that approach your setpoint would need to be hard coded into the profile.

Since most heating situations you want to be able to control the setpoint a rule is your best option. But I wanted to bring up the profile for completeness.

So to expand on Stephan’s example using Blockly you’d want something like this:

Obviously use your Items in place of mine. But notice that if the temp is between the setpoint and setpoint - 2, the heater remains ON or OFF. That’s your hysteresis.

Thank you,
i have had a bit of time this morning and found the solution.

Also created the widget as well

I intentionally added the qty blocks to make sure you compare values with units correctly.

Hi Miko,
Can you share the widget yaml code .

Thanks
Artur

uid: Termosztat_widget
tags: []
props:
  parameters:
    - context: item
      description: Fűtés bekapcsoló gomb
      label: Fűtés bekapcsoló gomb item
      name: itemHeaterONOFF
      required: true
      type: TEXT
    - context: item
      description: Tényleges hőmérséklet
      label: Tényleges hőmérséklet item
      name: itemCurrentTemp
      required: true
      type: TEXT
    - context: item
      description: Elérendő hőmérséklet
      label: Elérendő hőmérséklet item
      name: itemSettemp
      required: true
      type: TEXT
  parameterGroups: []
timestamp: Mar 2, 2024, 5:58:11 PM
component: f7-card
config: {}
slots:
  default:
    - component: f7-card-content
      slots:
        default:
          - component: f7-row
            config:
              class:
                - align-items-center
                - display-flex
                - justify-content-space-between
                - align-content-stretch
            slots:
              default:
                - component: f7-col
                  config:
                    class:
                      - display-flex
                      - align-items-center
                      - flex-direction-column
                  slots:
                    default:
                      - component: f7-icon
                        config:
                          class:
                            - margin-top
                          color: r
                          f7: thermometer
                          size: 36
                      - component: Label
                        config:
                          style:
                            fontSize: 20px
                          text: =(items[props.itemCurrentTemp].displayState || items[props.itemCurrentTemp].state )
                - component: f7-col
                  config:
                    class:
                      - display-flex
                      - align-items-center
                      - flex-direction-column
                  slots:
                    default:
                      - component: f7-icon
                        config:
                          class:
                            - margin-top
                          color: r
                          f7: gear_alt_fill
                          size: 36
                      - component: Label
                        config:
                          style:
                            fontSize: 20px
                          text: =(items[props.itemSettemp].displayState || items[props.itemSettemp].state )
    - component: f7-block
      config:
        class:
          - segmented
      slots:
        default:
          - component: oh-button
            config:
              action: command
              actionCommand: =Number(items[props.itemSettemp].state.split(' ')[0]) + 1
              actionItem: =props.itemSettemp
              class:
                - margin
              iconF7: plus
              iconSize: 25
              large: true
              raised: true
          - component: oh-button
            config:
              action: toggle
              actionCommand: ON
              actionCommandAlt: OFF
              actionItem: =props.itemHeaterONOFF
              active: "=(items[props.itemHeaterONOFF].state === 'ON') ? true : false"
              class:
                - margin
              iconF7: power
              iconSize: 25
              large: true
              raised: true
          - component: oh-button
            config:
              action: command
              actionCommand: =Number(items[props.itemSettemp].state.split(' ')[0]) - 1
              actionItem: =props.itemSettemp
              class:
                - margin
              iconF7: minus
              iconSize: 25
              large: true
              raised: true

@ tonicoveiro
This is the code for the widget. The words that you dont understand in the code are Hungarien

Thanks !!!