Trying to compare target and current temperature from TADO and switch Shelly2 as required

Not exactly sure where I’m going wrong with this. What I am trying to do is compare the main bedroom temperature with the main bedroom target temperature and switch a shelly2 switch as required if the temperature is less than the target temperature but I am getting errors when I check the config.
Any help would be appreciated

  sensor:
- platform: template
  sensors:
    main_bed_current_temp:
        friendly_name: 'Main Bedroom Current Temperature'
        value_template: "{{ states.climate.main_bedroom.attributes.current_temperature }}"
    conan_bed_current_temp:
        friendly_name: 'Conan Bedroom Current Temperature'
        value_template: "{{ states.climate.conan_bedroom.attributes.current_temperature }}"
    main_bed_temp_target:
        friendly_name: 'Main Bedroom Target Temperature'
        value_template: "{{ states.climate.main_bedroom.attributes.temperature }}"
    conan_bed_temp_target:
        friendly_name: 'Conan Bedroom Target Temperature'
        value_template: "{{ states.climate.conan_bedroom.attributes.temperature }}"        
    
    

  trigger:
- platform: template
  data_template: '{{ Main Bedroom Target Temperature > Main Bedroom Current Temperature }}'
  condition:
  action:
- service: homeassistant.turn_on
  entity_id: switch.shelly2_switch1

Sorry, should have included the error

Invalid config for [automation]: [sensor] is an invalid option for [automation]. Check: automation->sensor. (See /config/configuration.yaml, line 120). Please check the docs at https://home-assistant.io/components/automation/ Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->platform. (See /config/configuration.yaml, line 120). Please check the docs at https://home-assistant.io/components/automation/

Can you format your config per the blue bar at the top of the post?

Apologies, I thought I had. Edited now

sensor:
  - platform: template
	sensors:
      main_bed_current_temp:
	    friendly_name: 'Main Bedroom Current Temperature'
		value_template: "{{ states.climate.main_bedroom.attributes.current_temperature }}"
	  conan_bed_current_temp:
	    friendly_name: 'Conan Bedroom Current Temperature'
	    value_template: "{{ states.climate.conan_bedroom.attributes.current_temperature }}"
	  main_bed_temp_target:
	    friendly_name: 'Main Bedroom Target Temperature'
	    value_template: "{{ states.climate.main_bedroom.attributes.temperature }}"
	  conan_bed_temp_target:
	    friendly_name: 'Conan Bedroom Target Temperature'
        value_template: "{{ states.climate.conan_bedroom.attributes.temperature }}"        
    
automation:     
  - alias: ENTER NAME HERE
	intial_state: on
    trigger:
      - platform: template
        value_template: '{{ Main Bedroom Target Temperature > Main Bedroom Current Temperature }}'
    condition:
    action:
      - service: switch.turn_on
        entity_id: switch.shelly2_switch1

Review the above against your config.

Note the changes in spacing. I am not 100% sure that the two space indention before - platform: template is needed, however, it doesn’t hurt, it just the way I have done it. See the below link for more help with YAML and spacing.

Down to the automation section you are missing automation: That needs to be before all your automations. The exception to this is if you have a separate yaml file for automations in which case this shouldn’t be mixed with the sensors above.

Note the spacing changes again.

Next is data_template vs. value_template follow the docs on which to use where.

You don’t need the condition line if you are going to be including conditions.

homeassistant.turn_on works in a lot of cases but not all. Its best to use the actual platform you are trying to turn on/off so switch.turn_on makes more sense here.

Final bit, I dont have an instance accessible so I don’t know if your template will work.

Use the template tool in the dev tools in the left hand pop out menu to test your template.

When you template returns true the automation will trigger, if it returns false it won’t.

Thanks for the help and advice, I re-read your suggestions and tried your code, however I’m now getting the following error.

Invalid config for [automation]: [sensor] is an invalid option for [automation]. Check: automation->sensor. (See /config/configuration.yaml, line 120). Please check the docs at https://home-assistant.io/components/automation/

Do I need to put the sensor templates in a separate file?

Aside from the indentation errors, I doubt the automation’s value_template is functional. You need to specify entity_id’s in the template, not an entity’s friendly_name.

Try this:

sensor:
  - platform: template
    sensors:
      main_bed_current_temp:
        friendly_name: 'Main Bedroom Current Temperature'
        value_template: "{{ state_attr('climate.main_bedroom', 'current_temperature') }}"
      conan_bed_current_temp:
        friendly_name: 'Conan Bedroom Current Temperature'
        value_template: "{{ state_attr('climate.conan_bedroom', 'current_temperature') }}"
      main_bed_temp_target:
        friendly_name: 'Main Bedroom Target Temperature'
        value_template: "{{ state_attr('climate.main_bedroom', 'temperature') }}"
      conan_bed_temp_target:
        friendly_name: 'Conan Bedroom Target Temperature'
        value_template: "{{ state_attr('climate.conan_bedroom', 'temperature') }}"        
    
automation:     
  - alias: ENTER NAME HERE
    intial_state: on
    trigger:
      - platform: template
        value_template: '{{ (sensor.main_bedroom_target_temperature | float) > (sensor.main_bedroom_current_temperature | float) }}'
    action:
      - service: switch.turn_on
        entity_id: switch.shelly2_switch

It passes Config Check but has not been tested for functionality.

What file are they in currently?

Thanks for all the help. It got me on the right path and I have a good start now.

Here is what I ended up with. Probably not as neat as could be but it is working :smiley:

It brings my Oil Range switch on if either of the TADO valves drops below it’s set temperature and switches off the range once both stats are above their set value. I’ll have a lot more tweaking to do with this but it feels like a good start

`- id: '1547161734755'

alias: range On
trigger:

  • platform: template
    value_template: ‘{{ (state_attr(’‘climate.main_bedroom’’, ‘‘temperature’’) > state_attr(’‘climate.main_bedroom’’, ‘‘current_temperature’’)) or (state_attr(’‘climate.conans_bedroom’’, ‘‘temperature’’) > state_attr(’‘climate.conans_bedroom’’, ‘‘current_temperature’’)) }}’
    action:
  • service: switch.turn_on
    entity_id: switch.shelly2_switch1
  • id: ‘1547342294082’
    alias: range off
    trigger:
    • platform: template
      value_template: ‘{{ state_attr(’‘climate.main_bedroom’’, ‘‘temperature’’) < state_attr(’‘climate.main_bedroom’’, ‘‘current_temperature’’) and state_attr(’‘climate.conans_bedroom’’, ‘‘temperature’’) < state_attr(’‘climate.conans_bedroom’’, ‘‘current_temperature’’) }}’
      action:
    • service: switch.turn_off
      entity_id: switch.shelly2_switch1`