I am using the following component to read a value from a file.
Every time the value changes I would like the following to happen.
If the value is below 100,000 do nothing
If the value is between 100,000 and 199,999 play audio file “alarm1.mp3”
If the value is between 200,000 and 299,000 play audio file “alarm2.mp3
If the value is above 300,000 paly audio file “alarm3.mp3”
Any help on how to script this behavior in the automations.yaml file would be most appreciated.
Which is it? The documentation says media_play in one place and play_media in another. When I checked my log I see that the registered service was media_play:
2018-11-01 10:07:24 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=media_play, domain=media_player>
Below is the script that I am using and it is working well with Google Home.
The only thing to note is that the IP adress of the audio files has to be public in order for Google Home to be able to play the audio file.
alias: Alarm
trigger:
entity_id: sensor.file_value
platform: state
condition:
condition: numeric_state
entity_id: sensor.file_value
above: 99999
action:
service: media_player.play_media
entity_id: media_player.kontor
data_template:
media_content_type: ‘audio/mp3’
media_content_id: >
{% set val = trigger.to_state.state|int %}
{% if val < 200000 %}
alarm1.mp3
{% elif val < 300000 %}
alarm2.mp3
{% else %}
alarm3.mp3
{% endif %}