I’m trying to make a simple alarm system with Xiaomi gateway a door sensor and a wireless switch.
The thing I’m trying to achieve :
Press single click, set alarm after 60 seconds.
Door open -> wait 10 seconds -> trigger alarm for 10 minutes or until disarmed with long press.
It kinda works, I found 1 problem with it, after 5-6 seconds, the gateway stops playing the alarm ringtone. HA stays it is in “triggered” state and I can see it is alarming, but sound stops. Tried to increase trigger_time but no sound at all.
Xiaomi Gateway ring tones don’t repeat and have only a few seconds duration.
You can upload a bigger file to the gateway to use instead
Or copy/paste the service: xiaomi_aqara.play_ringtone as many times as you want it to play/repeat
Try this and use the input_boolean as the alarm trigger.
I had a look at the post from @pplucky and looks great for this kind of things and if it is outdated shouldn’t be very hard to fix.
Thank you pplucky!
Now I have time for a round 2, most of the errors was easy to fix, like changing to service to xiaomi_aqara.play_ringtone and so on.
The other thing was you used a different script name in example than in automation, it was easy too after read the log files.
I will give it another shot, but I don’t get this error message.
Script script.play_sound already running.
8:55 components/script.py (WARNING)
Script script.play_sound already running.
8:55 components/script.py (WARNING)
Error executing service <ServiceCall script.play_sound: ringtone_vol=1, ringtone_id=10, delay=2>
8:55 helpers/template.py (ERROR)
Error rendering data template: UndefinedError: 'None' has no attribute 'state'
8:55 helpers/service.py (ERROR)
# Stop sound when alarm is disarmed or armed ###
- alias: "Alarm Turn off or Armed"
trigger:
- platform: state
entity_id: alarm_control_panel.riaszto
to: 'disarmed'
- platform: state
entity_id: alarm_control_panel.riaszto
to: 'armed_away'
- platform: state
entity_id: alarm_control_panel.riaszto
to: 'armed_home'
action:
# Turn on gateway mute NOT to play sound ###
- service: input_boolean.turn_on
data:
entity_id: input_boolean.mute_gateway_sounds
# Stop ringtone sound --> didn't seem to work due to loop ###
- service: xiaomi_aqara.stop_ringtone
data:
gw_mac: !secret xiaomi_mac
# Wait 10 seconds & then turn off gateway mute ###
- delay:
seconds: 10
- service: input_boolean.turn_off
data:
entity_id: input_boolean.mute_gateway_sounds
# Alarm trigger while armed away ###
- alias: "Alarm trigger while armed away"
trigger:
# Front Door opened ###
- platform: state
entity_id: binary_sensor.door_window_sensor_158d00011234
to: 'on'
# Any movement detected ###
# - platform: state
# entity_id: group.all_motion
# to: 'on'
# Alarm status is armed away ###
condition:
condition: state
entity_id: alarm_control_panel.riaszto
state: 'armed_away'
action:
# Turn off gateway mute to play sound ###
- service: input_boolean.turn_off
data:
entity_id: input_boolean.mute_gateway_sounds
# Trigger alarm ###
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.riaszto
# Play ringtone sound in loop ###
- service: script.play_sound
data:
ringtone_id: 8
ringtone_vol: 1
delay: 6
This is all due to the fact that you did not copy the full code and did not include input_slider.gateway_volume, input_select.gateway_sound and input_slider.loop, which are used in the scripts called in automation.
If you don’t want those dynamic, you need to adapt your configuration a bit more.
Thans for the reply, tried it now, all the inputs are there, and I even changed ‘input_slider’ to ‘input_number’, because it said it changed.
The same errors are still there.
Error executing service <ServiceCall script.play_sound: delay=2, ringtone_vol=1, ringtone_id=10>
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 131, in async_render
return self._compiled.render(kwargs).strip()
File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/filters.py", line 653, in do_int
return int(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1010, in _event_to_service_call
yield from service_handler.func(service_call)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/script.py", line 163, in service_handler
yield from script.async_turn_on(variables=service.data)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/script.py", line 215, in async_turn_on
yield from self.script.async_run(kwargs.get(ATTR_VARIABLES))
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 105, in async_run
delay.async_render(variables))
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 133, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'
### Play Provided sound in loop on Gateway ###
script:
play_sound:
alias: "Play Sound"
sequence:
### Turn off gateway mute to play sound ###
- condition: state
entity_id: input_boolean.mute_gateway_sounds
state: 'off'
### Play ringtone sound provided ###
- service: xiaomi_aqara.play_ringtone
data_template:
gw_mac: !secret xiaomi_mac
ringtone_id: "{{ ringtone_id }}"
ringtone_vol: "{{ ringtone_vol }}"
### Wait & call another script that call this one ###
### in order to generate an infinite loop until gateway ###
### mute is turned on by some other action ###
- delay: '00:00:{{ delay | int }}'
- service: script.play_sound_loop
data_template:
ringtone_id: "{{ ringtone_id }}"
ringtone_vol: "{{ ringtone_vol }}"
delay: "{{ delay }}"
play_sound_loop:
alias: "Play Sound in Loop"
### Wait & call script that called this one ###
### in order to generate an infinite loop until ###
### gateway mute is turned on by some other action ###
sequence:
- delay: '00:00:{{ delay | int }}'
- service: script.play_sound
data_template:
ringtone_id: "{{ ringtone_id }}"
ringtone_vol: "{{ ringtone_vol }}"
delay: "{{ delay }}"
With these scripts, you don’t actually need the input_slider.gateway_volume, input_select.gateway_sound and input_slider.loop, but you need to test it yourself.
Yes I do, but I am not sure that my full alarm code is posted, as I remember that the purpose of the example was just to show that ringtone loop was somehow possible.
I can check it later and share, if you’re interested.
As I mentioned, it should play a sound while it is pending and then another if it is armed, just like a regular home alarm.
When you arm it, while it is not armed (=pending), it should play a sound for me to know I still have time to leave before it is armed.
When alarm is triggered, another alarm sound is to be played (isn’t that the purpose of an alarm?).