Doing math in scripts

I have an Ecobee 3 thermostat, and I’d like to include a simple way to bump up the temperature by 3 degrees (F) - something for my wife to click when she just feels chilly. I can get an acceptable (not ideal) user interface by writing a script, and then including script:thermostat_increase_3 in a group.

But I can’t get the script to let me do inline math. I’m feeling very stupid; I’m a newbie.

Comments inline below show both what I want and some things I’ve tried.

# In scripts.yaml
thermostat_increase_3:
   alias: Increase 3 degrees
   sequence:
     - service: climate.set_temperature
       data:
         entity_id: climate.myecobee
	     # Next line WORKS but doesn't accomplish what I want
	     # temperature: 70
	     # Simple test fails, doing any kind of math fails with "expected float for dictionary value @ data['temperature']. Got '65.1 + 10.1'"
         temperature: 65.1 + 10.1
	     # Next line is what I'm actually trying to do; it fails with "expected float"
         # temperature: (3 + states.climate.myecobee.attributes.temperature )

I’ve tried a stupid number of iterations of brackets and curly brackets and | floats and can’t get anywhere.

Help, please?

- service: climate.set_temperature
  data_template:
    entity_id: climate.myecobee
    temperature: '{{states.climate.myecobee.attributes.temperature | float + 3}}'

did you change data to data_template?

I missed that change the first time. I made it now, and it works!

Thank you!

(off to read about data_template)

start here:

Thank you. I’d stared at the Service Calls example for a long time, but was missing the distinction between “data” and “data_template”. I see now that’s the focus of that last example on the page, but I was missing it.

I’m at the newbie phase where everything is new. I’ve written some major apps in DJango, so templating isn’t new to me. It’s a powerful feature.

Also might want to look into making the leap into appdaemon. Then you’re in python and have all that power available to you.

I just saw a link to appdaemon this morning, for the first time. Given I’m comfortable in Python it looks like a nice place to be.

Thanks.

1 Like