Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 105589

Weatheralerts integration - Make tts.google_translate_say skip reading an attribute of a weather alert if it is set to none

$
0
0

I have the weatheralerts custom integration from hacs (GitHub - custom-components/weatheralerts: A sensor that gives you weather alerts from alerts.weather.gov.) set up and working, but have hit a minor roadblock in code syntax.

If a weather alert comes up for my location, I have successfully programmed Home Assistant to leverage Google Translate Say to read the ‘spoken title’ attribute of the alert. However, there could be up to 5 total weather alerts at one time, so I wanted Google to check and read out all five. It works, but one minor annoyance is if there are no weather alerts for the other sensors, Google just says “None”.

How should I modify this code to only read weather alerts 2-5 if the value is not none?

    - service: tts.google_translate_say
        entity_id: media_player.sonos_bedroom
        data_template:
          message: |
            '"{{ state_attr("sensor.weatheralerts_1_alert_1", "spoken_title") }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_2", "spoken_title") }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_3", "spoken_title") }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_4", "spoken_title") }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_5", "spoken_title") }}"'

I tried this, but it only reads back “True” if there are no alerts (strange):

      - service: tts.google_translate_say
        entity_id: media_player.sonos_bedroom
        data_template:
          message: |
            '"{{ state_attr("sensor.weatheralerts_1_alert_1", "spoken_title") }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_2", "spoken_title") != 'none' }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_3", "spoken_title") != 'none' }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_4", "spoken_title") != 'none' }}"'
            '"{{ state_attr("sensor.weatheralerts_1_alert_5", "spoken_title") != 'none' }}"'

Thank you all in advance for your feedback and help.

Special thanks to SlackerLabs for his awesome tutorial on this integration (Add NWS Weather Alerts to Home Assistant - YouTube).

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 105589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>