Hassio automation template formatting question

Hello, I need some advise/help in yaml template formatting.

To learn to use yaml, I started by trying to implement a furnace control. I have a Sonoff-sv controlling the furnace and a Sonoff-TH reporting the temperature(mqtt). I want to compare the temperature to a set point on a panel slider, and with hysteresis, turn the furnace on/off. In addition, I want to turn off the furnace after a set time from a slider on the panel compared to a counter incremented each minute. I have tried for a week and failed. Value templates that work in the template tool, fail in operation yielding errors in the log file. The log file language is not very easy to understand. I tried state.xxx.state and float(state.xxx.state) and operators ‘gt’, ‘lt’, and ‘ge’ which all failed. I show example code below and I have attached my yaml files. Sometimes, I find hundreds of lines of nulls in the log file between the top and any error messages. I have completely started over with a freshly programmed, new Sandisk class 10, 64 Gb SD card with hassio 0.63.3 and new clean yaml files and database files. There was no improvement.

I would really appreciate any advise. I program in assembly, C, C++, and Python, but that is not helping me much here.

indent preformatted text by 4 spaces
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: input_boolean.og_furnace_run
      state: 'on'
    - condition: template
      value_template: '{{ (states.counter.og_furnace_timer.state) > (states.input_number.og_furnace_ontime.state) }}'
	 
condition:
 condition: and
 conditions:
   -  condition: template
      value_template: '{{ float(states.input_number.og_furnace_temp_set.state) > float(states.sensor.shop_ac_temperature.state) }}'
   -  condition: state
      entity_id: input_boolean.og_furnace_run
      state: 'on'
	
 condition:
   -  condition: template
      value_template: '{{ gt(states.input_number.og_furnace_temp_set.state, states.sensor.shop_ac_temperature.state + 2.5) }}'
   -  condition: state
      entity_id: input_boolean.og_furnace_run
      state: 'on'

indent preformatted text by 4 spaces

If you want help with your configuration yaml, you need to format it properly for us to read it.

Sorry, I did not see how to attach the files. After your comment, I learned how to upload the yaml files which are given below.:wink:

I really want to understand how to compare a value from a slider on the panel to a sensor value (like temp > set point). What is the syntax for that?:thinking:

automations.yaml (4.5 KB)

configuration.yaml (11.8 KB)

We don’t need files attached, but we need the formatting done correctly using the instructions at the top of every page that explains how to properly format your code using the forum software.

I think your problem is that you need some ‘if’ statements in there.

value_template: '{% if(states.counter.og_furnace_timer.state > states.input_number.og_furnace_ontime.state) %}true{%endif%}'

This may not be exact, but should be close

1 Like

nope, don’t need the if. That will break the value templates. Value templates are ment to return a True/False for condition. If you add the if, then it removes the returned true/false from the value template.

You can disregard this comment. I didn’t read your full value template.

1 Like

Personally, I turn all my condtions into a single condition to avoid the 'and’s and 'or’s:

This is your example:

  condition: and
  conditions:
    - condition: state
      entity_id: input_boolean.og_furnace_run
      state: 'on'
    - condition: template
      value_template: '{{ (states.counter.og_furnace_timer.state) > (states.input_number.og_furnace_ontime.state) }}'

This is how I like to write it to get away from multi conditions in yaml:

condition:
  condition: template
  value_template: >
    {{ is_state('input_boolean.og_furnace_run', 'on') and states.counter.og_furnace_timer.state | float > states.input_number.og_furnace_ontime.state | float }}

or

condition:
  condition: template
  value_template: "{{ is_state('input_boolean.og_furnace_run', 'on') and states.counter.og_furnace_timer.state | float > states.input_number.og_furnace_ontime.state | float }}"

or

condition:
  condition: template
  value_template: >
    {% if is_state('input_boolean.og_furnace_run', 'on') %}
      {% if states.counter.og_furnace_timer.state | float > states.input_number.og_furnace_ontime.state | float %}
        True
      {% else %}
        False
      {% endif %}
    {% else %}
       False
    {% endif %}

Choose your poison, any of them will get you the same result.

1 Like

Gentlemen, that is great. I believe you have given me enough to succeed:sunglasses:

I will now go off and implement with my new understanding. I will reply when I have tested my implementation.

Thank you very much for your help.

1 Like

Nice! Now my furnace control works! Great! Thank you so much for showing me how to do this.:smile: