Pump Control

Hi
I posted on the 3rd May about differential temperature pump control. I have since tried to correct the YAML script without success. I have an error “Invalid YAML syntax: mapping values are not allowed here” line 56 col 23 (value_template:). Any help in resolving my problem will be much appreciated.
Script here.

esphome:
  name: "ha_diff_temps_test"
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.102
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ha Diff Temps Test"
    password: "xxxxxxxxxxxx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret api

ota:
  password: !secret ota

dallas:
  - pin: 23

# Individual Sensors
sensor:
  - platform: dallas
    address: 0xb80000030864ca28
    name: "panel"
    id: "panel"

  - platform: dallas
    address: 0x60000003084c2b28
    name: "tank"
    id: "tank"

  - platform: value_template
    id: Temperature Difference
    unit_of_measurement: °C
    update_interval: 60s
    lambda: 'return id(panel).state - id(tank).state;'

  - platform: template
    sensors:
    temp_diff:
      friendly_name: Temperature Difference
        value_template: >
          {% if ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            < (states.input_number.pump_on_offset.state | float ) %} pump_off
          {% elif ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            > (states.input_number.pump_on_offset.state | float ) %} pump_on
          {% else %} pending {% endif %}

input_number:
  pump_off_offset:
    name: Pump OFF offset
    initial: 0.1
    min: 0
    max: 2
    step: 0.1

  pump_on_offset:
    name: Pump ON offset
    initial: 3
    min: 0
    max: 2
    step: 0.5

automation:
  - id: ID12
    alias: 'Pump hot water if hotter than tank - stop if not'
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: sensor.temp_diff
    action:
      entity_id: switch.solar_pump
      service_template: >
        {% if is_state ('sensor.temp_diff' , 'pump_on') %} switch.turn_on
        {% else %} switch.turn_off {% endif %}

Regards Adhoc77

You have an indentation problem. Should be

  - platform: template
    sensors:
      temp_diff:
        friendly_name: Temperature Difference
        value_template: >
          {% if ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            < (states.input_number.pump_on_offset.state | float ) %} pump_off
          {% elif ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            > (states.input_number.pump_on_offset.state | float ) %} pump_on
          {% else %} pending {% endif %}

Hi micque
Thanks for your quick reply. I have altered the code. I now have the following errors.
line 46 platform not found ‘sensor.value_template’.
line 54 sensors is an invalid option for [sensor.template]. Check indentation.
line 64 Component not found: input_number.
line 79 Component not found: automation.
Any ideas?
Cheers Adhoc77

Try this and make sure that your {% if …%} are in one line.

The following code MUST be on your configuration.yaml in Home Assistant with the input_number and the automation.

  - platform: template
    sensors:
      temp_diff:
        friendly_name: Temperature Difference
        value_template: >
          {% if ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            < (states.input_number.pump_on_offset.state | float ) %} 
            'pump_off'
          {% elif ((states.sensor.panel_temperature.state | float ) -  (states.sensor.tank_temperature.state | float))
            > (states.input_number.pump_on_offset.state | float ) %} 
             'pump_on'
          {% else %} 
             'pending' 
          {% endif %}


Hi
laca75tn
Adjusted the code as suggested, but made no difference. The errors are the same.
Many thanks
Adhoc77

Do you have all that code on the esphome yaml? Check my edited comments on my previous post.

  - platform: value_template
    id: Temperature Difference
    unit_of_measurement: °C
    update_interval: 60s
    lambda: 'return id(panel).state - id(tank).state;'


#THIS IS THE END OF THE ESPHOME CODE  ANYTHING BELOW THIS LINE MUST BE ON HOME ASSISTANT

  - platform: template
    sensors:
    temp_diff:
      friendly_name: Temperature Difference
        value_template: >
          {% if ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            < (states.input_number.pump_on_offset.state | float ) %} pump_off
          {% elif ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float))
            > (states.input_number.pump_on_offset.state | float ) %} pump_on
          {% else %} pending {% endif %}

Hi laca75tn
Thank you for persevering with this, as you may have guessed I am new to HA etc. I did read your post incorrectly. I have now placed the code as you suggested in the /config/configuration.yaml file using the file editor.
I now get the following errors esphome code. line 46 platform not found ‘sensor.value_template’.
In the configuration.yaml file I get, the error duplication mapping key at line 46, col-373 automation.
Should I have placed the automation code in the /config/automations.yaml file?
Many thanks again for your help.
Adhoc77

That’s because there is no value_template platform in esphome. Value_template is a ha yaml thing but the lambda statement is definitely esphome. Are you copying this from somewhere?

my way of fixing value_template errors
is to paste into the Developer Tools -> TEMPLATE

ie

((states.sensor.panel_temperature.state | float )

in template

{% set val1 = states.sensor.panel_temperature.state | float %}

{{val1}}

as i dont have same sensors it will error but your should not praying

then
make a bit longer

{% set val1 = ((states.sensor.panel_temperature.state | float ) - (states.sensor.tank_temperature.state | float)) %}

{{val1}} <= Should show new value

bla bla

my first value_template

         {% set Car = states('sensor.car_spot_1')|int(1000) %}
         {% if (Car<200) %}
         Home
         {% else %}
         Away
         {% endif %}

just built it up and it learnt each bit LOL

Hi micque
I did indeed use the code from xbmcnut & mf_social from Feb2018. I did acknowledge them in my post of 3rd May 2020.
Adhoc77

No worries. I only ask because originally I thought you were providing excerpts of several files both HA and esphome for consideration. Clearly that wasn’t your intent but likely that’s what the original author was doing.
The platform value_template section is neither HA nor esphome. Lambda is clearly esphome but the rest of it could be either. Perhaps the value_template is supposed to be template? That could work I think and perhaps it was a typo on the part of the original author.