New to Home Assistant - help needed on automation

Hi there.
I am all new to Home Assistant and have just gotten up and running with the newest hassio on a Rasberry Pi + a AEOTEC Z-stick and two Telldus Plug-in switched (zwave) + a temperature sensor.

I can make a script that turns both plugs on or both plugs off pretty easy:

'1543157624607':
  alias: Turn heat off
  sequence:
  - alias: ''
    data:
      entity_id: switch.telldus_tzwp100_plugin_switch_switch
    service: switch.turn_off
  - data:
      entity_id: switch.telldus_tzwp100_plugin_switch_switch_2
    service: switch.turn_off
'1543159109134':
  alias: Turn Heat on
  sequence:
  - data:
      entity_id: switch.telldus_tzwp100_plugin_switch_switch
    service: switch.turn_on
  - data:
      entity_id: switch.telldus_tzwp100_plugin_switch_switch_2
    service: switch.turn_on

I am however struggling with making the automation script for it. I cant figure out how to make a script that compares two readings from my temperature sensor (current temperature, and set temperature is “climate.danfoss_rs_room_sensor_heating.current_temperature” and “climate.danfoss_rs_room_sensor_heating.temperature”) and triggers if the first is higher than the other.

What i want to do is this:

if climate.danfoss_rs_room_sensor_heating.current_temperature < climate.danfoss_rs_room_sensor_heating.temperature
then trigger the turn on script

if climate.danfoss_rs_room_sensor_heating.current_temperature > climate.danfoss_rs_room_sensor_heating.temperature
then trigger the turn off script

Anyone that can help with some pointers or samples that look like this? (it is “greater than” or “less than” that i am struggling with…

What that works i would want to include “if door open - do not run the turn on script”

You can try something like the following. You’ll have to verify all of your entities and states:

automation:
  alias: Turn On Heat
  trigger:
    platform: template
    value_template: '{{ states.climate.danfoss_rs_room_sensor_heating.current_temperature.state|float < states.climate.danfoss_rs_room_sensor_heating.temperature.state|float }}
  condition:
    condition: state
    entity_id: switch.door
    state: 'open'
  action: 
    service: script.turn_on
    entity_id: script.heat_turn_on

Then do the opposite for turning off the heat.

EDIT after @petro added the comment below:

I’m not sure where the entities you listed came from but you need to make sure those exist. They may also be listed under attributes of the entity. That will change the template if so.

1 Like

this doesn’t seem right. Too many dots? Don’t have a thermostat so I could be wrong

you’re right. I didn’t see the extra dot in there.

But I did warn to verify entities. :wink:

Thanks i will check it out. Need to read a little on the template usage as well to understand what you are suggesting :slight_smile:

Just thought i would give an update to what actually worked.

I have to say these scripts and automations files sure are picky when it comes to indentation and spaces…spent quite a few hours getting it right and getting the right values out of the entities (and their attributes…)

btw: Anyone knows if i can set the value of an attribute in an entity (and actually have it write that value to the entity) ? ie. During night i would like to decrease the set value for the temp by 3 degrees

This is what i ended up with:

- id: '1543679779639' 
  alias: Turn Heat off
  trigger:
  - platform: template
    value_template: '{{(states.sensor.danfoss_rs_room_sensor_temperature.state|float)
      > (states.climate.danfoss_rs_room_sensor_heating.attributes.temperature|float)}}'
  condition: []
  action:
  - data: {}
    service: script.1543157624607
  - data: {}
    entity_id: input_boolean.ovn_paa
    service: input_boolean.turn_off

- id: '1544131478526'  
  alias: Turn Heat Off
  trigger:
  - platform: template
    value_template: '{{(states.sensor.danfoss_rs_room_sensor_temperature.state|float)
      < (states.climate.danfoss_rs_room_sensor_heating.attributes.temperature|float)}}'
  condition: []
  action:
  - data: {}
    service: script.1544278387808
  - data: {}
    entity_id: input_boolean.ovn_paa
    service: input_boolean.turn_on

The people who volunteer their time to help others are also picky about indentation and spaces. :slight_smile:

Please format your code as per finity’s helpful gif.

Did try that :slight_smile:

Thanks! Now that your code is formatted we can conclude that indentation and spaces really do matter! Check out the examples here to get an idea of what’s wrong.

Yeah, the indents on the last code you posted are wrong all over the place.

you probably ought to correct those errors so in case anybody comes along and uses your “working” code and they get errors on the config check it won’t confuse them more.

what’d you use to make that vid?

That particular gif has been making the rounds on this forum:
https://community.home-assistant.io/search?q=code%20format%20example.gif

FWIW, on Windows 10, this free, open-source utility does a nice job of screen-recording with an option to save in gif format: https://www.screentogif.com/

I was looking for something like this for another project. Thanks for the link.

Yes, that’s what I used. Works good.

1 Like

Thanks for your tips. It worked out in the end. The code listed is now working as its supposed to.
I ended up adding a boolean thats true if the heat is on. I use this to check whether to swich heat back on once an open door returns to state “off”.

Yeah, I made that because it seemed easier than trying to explain how to use the box at the top all the time.

I’ve reached out to a couple of moderators to get it incorporated into the blue box but for some reason it hasn’t gained any traction there.

FWIW, I’d vote for replacing the existing static demo, with your animated version, ONLY if there was a way for me to hide it.

I’m long past the need for the code-formatting tip and prefer to regain some screen real-estate by hiding that box. Replacing it by an even larger box (containing an animated demo), would not be something I’d support (unless I could hide it).

I think it could be done without taking up much, if any, more screen space.

I haven’t gotten any feedback from the people I’ve talked to about using it but maybe that’s why it hasn’t been done as it is.

Maybe I’ll play around with it to see if I can shrink it and still make it usable.

The Blue Box is unfortunately a necessary evil. the good thing is that it gets auto hidden after you scroll down a few posts. :smiley: