Asking Alexa for information

I did create the last_called sensor and also added 0.5 delay before the update_last_called and before the notify.alexa_media_last_called which did seem to help and yes they are the older echoes without the cloth so maybe that was why.

  action:
  - delay:
      seconds: 0.5
  - service: alexa_media.update_last_called
  - delay:
      seconds: 0.5
  - service: notify.alexa_media_last_called
    data:
      message: >-
        {% if (state_attr('light.dialog', 'brightness') | int / 255 * 100 ) | int == 10  %}
          The battery is currently at {{ states('sensor.solar_battery_soc') }} percent
        {% elif (state_attr('light.dialog', 'brightness') | int / 255 * 100 ) | int == 20  %}
          The EV battery is currently at {{ states('sensor.charging_level_hv') }} percent
        {% elif (state_attr('light.dialog', 'brightness') | int / 255 * 100 ) | int == 30  %}
          The electric range is {{ states('sensor.remaining_range_electric') }} kilometers
        {% else %}
          There is no routine set up for that value.
        {% endif %}
      data:
        type: tts
  - service: light.turn_off
    entity_id: light.dialog

I have also added two more routines but for some reason this one doesnā€™t work {% elif (state_attr('light.dialog', 'brightness') | int / 255 * 100 ) | int == 30 %} keeps going down to the there is no routine set up bit and I have no idea why, the brightness is set to 30 in the routine itself.
Can anyone spot anything incorrect (the value of that sensor is 0 at this moment)

The code looks fine, but check the arithmetic that comes out of your template if you paste it into the template editor in Developer Tools.

Just paste {{ (state_attr('light.dialog', 'brightness') | int / 255 * 100) | int }} into the template editor, trigger Alexa to run the range routine, and make sure the output from the template is actually returning 30. Sometimes you can get weird rounding errorsā€¦ 30% of 255 is 76.5 rounded up it works, rounded down it fails:

{{ ((76.5)|int / 255 * 100) | int }} returns 29

If thatā€™s what you see in the template editor, your options are to just change whatā€™s after ā€œ==ā€ to 29, or to modify your templates to compensate by rounding:

{% elif ((state_attr('light.dialog', 'brightness') | int) / 255 * 100) | round() | int == 30 %}

I would suggest modifying the templates since you could run into similar arithmetic issues if you create messages for 50%, 70%, and 90%.

Yup that was it, coming back as 29 and now 30 with the round() and works ok, thanks :slight_smile:

Based on your Ideaā€™s iā€™ve create a Node-Red Version of your Sequence:

(Dummy, Trigger and Condition Handling does Node-Red)

Thanks! :slight_smile:

Hi @sd_dracula (or anybody else!)

I donā€™t know if this is the right way / done thing, but Iā€™m a fairly new HA adopter, loving it, but looking for some help. Iā€™m pretty much wanting to do exactly the same as you attempted in this thread. But Templates and Media Player are very very much on the fringe of my skills. Iā€™ve made solid headway into implementing the solution here but am stuck at what i feel is the final hurdle (and am prob only about 70% understanding how this actually works!)

Would it be possible to get some advice / assistance? Iā€™d really appreciate it!

Thanks if you can!