How do I pass a value with emailsend service

Hi,

I try to create an automation which send me an email with an entity value each last day of month.
But I am totally lost. I can’t get along with trigger.to_state.state
Maybe someone is able to help me with the automation.

My last attempt thrown the error:
Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'

Automation yaml:

alias: senden email with monthly value water costs 
description: ""
mode: single
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.ha
  - platform: state
    entity_id: sensor.cost_month_water_total
condition: []
action:
  - service: notify.emailsend
    data:
      message: |-
        total cost of water:
         {{ trigger.to_state.state }} EUR
      title: total cost of water

Even if I ignore the calendar trigger, how do I get the sensor value passed into the email?

Thanks

Why don’t you use a reference directly to your sensor instead of using the trigger variable? So it will support the trigger based on the calendar also.

Something like this:

alias: senden email with monthly value water costs 
description: ""
mode: single
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.ha
  - platform: state
    entity_id: sensor.cost_month_water_total
condition: []
action:
  - service: notify.emailsend
    data:
      message: |-
        total cost of water:
         {{ states('sensor.cost_month_water_total') }} EUR
      title: total cost of water

And you probably don’t want to get an email every time the value changes (which will happens if you use the sensor itself as a trigger), so maybe you should have only the calendar based trigger.

Something like this:

alias: senden email with monthly value water costs
description: ""
mode: single
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.ha
condition: []
action:
  - service: notify.emailsend
    data:
      message: |-
        total cost of water:
         {{ states('sensor.cost_month_water_total') }} EUR
      title: total cost of water

Wooowww! so easy!
That’s what comes of it, I followed a wrong lead and then didn’t try anything else.

Thank you very much!!

1 Like