One state used in two automation actions but different behaviour/values?

Hi All,

In an automation that keeps track of daily energy usage, I have setup two actions in the same automation, one to send a notification with the energy used and next and ifttt trigger to write it into a Google Spreadsheet.

The notification shows the correct values for the calculated readings, the spreadsheet shows the literal string of the value I am trying to send, i.e:

- service: notify.pushover
    data_template:
      title: "Meterstanden"
      message: "Verbruikt op {{ now().year }}-{{ now().month }}-{{ (now().day)-1 }}. Hoog: {{ states('input_number.24hour_power_consumption_normal_tarrif') }} kWh, Laag: {{ states('input_number.24hour_power_consumption_low_tarrif') }} kWh, Gas: {{ states('input_number.24hour_gas_consumption') }} m3. Min-temp: {{ states.sensor.pws_temp_low_1d_c.state }}C, Max-temp: {{ states.sensor.pws_temp_high_1d_c.state }}C"
  - service: ifttt.trigger
    data: {"event":"Meterstanden", "value1":"{{ states('input_number.24hour_power_consumption_normal_tarrif') }}", "value2":"{{ states('input_number.24hour_power_consumption_low_tarrif') }}", "value3":"{{ states('input_number.24hour_gas_consumption') }}"}

So, the notification shows the actual values of the meter readings, but the spreadsheet shows, literally (without quotes) “{{ states(‘input_number.24hour_gas_consumption’) }}” for example. If I take the double quotes away from the input_number values, the build fails (travis-ci).

I wonder what I am missing here…

The complete automation can be found at the bottom of this file:
https://github.com/aetjansen/HomeAssistant-Config/blob/master/packages/energy.yaml

Maybe data_template?

2 Likes

Your second service needs to be data_template instead of data like @anon43302295 said.

1 Like

Thanks, I’ll give that a go, never caught my eye that I had that difference there. What is the difference/reason for using data in one place and data_template elsewhere?

so regular data expects no jinja, just normal yaml. data_template will execute jinja, thats really the only difference.

2 Likes

Thanks! I have gone through some more automations to see what I did, I understand that using data_template without jinja in it, will work fine. But using data: with jinja in, will not.

Would there be a significant performance loss if data_template was used everywhere regardless of jinja being used?

probably not in the grand scheme of things. It may add some additional startup time. It also may add a few ms to the firing of your actions, but nothing really noticeable.

1 Like