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: