Thanks to everyone in this thread for the tips and initial scripts!
I was having an issue where @jerrm 's script would work but only on every other service call. I wasn’t able to figure out why this was the cause BUT I was able to fix it by modifying the script to normally toggle the siren if the melody hadn’t changed since the last call.
I also took the liberty of improving the UI experience and adding more defaults to the script to make usage easier.
Based on jerrm’s script and @Brubba 's setup steps from above here is the Idiot’s Guide to the ZHA Neo Siren:
STEP 1: Gather Setup Info and Variables
- Create an Input Text to save last used melody
- Settings → Services & Services → Helpers → Create Helper → Text
- Name:
neo_alarm_melody
- Name:
- Create
- Settings → Services & Services → Helpers → Create Helper → Text
- Get required device values
- Settings → Devices → Zigbee Home Automation → Devices → find the siren device and open device details page
- Device Info → Zigbee info → IEEE
- Example:
a4:c1:38:a0:19:76:33:8b
- Example:
- Controls → Switch
- Click on Switch to open its details → Gear icon → Look for Entity ID
- Example
switch.neo_siren_switch
- Example
- Click on Switch to open its details → Gear icon → Look for Entity ID
- Device Info → Zigbee info → IEEE
- Settings → Devices → Zigbee Home Automation → Devices → find the siren device and open device details page
You now have three pieces of information needed to set up the script:
- Input Text helper Entity ID you created EX
neo_alarm_melody - IEEE ID of the ZHA siren device EX
a4:c1:38:a0:19:76:33:8b - Siren Switch Entity ID (used to toggle siren) EX
neo_siren_switch
STEP 2: Setup Script
- Go to Settings → Automations & scenes → Scripts → Add Script → Create new script
- In the New Script page click “…” in the top right corner → Edit in YAML
- Delete the existing contents (or replace it) with the code below:
# based on https://community.home-assistant.io/t/zigbee-neo-siren-ab02b2-v2-trying-to-switch-melody/425552/8
#
# This script includes these improvements:
#
# * Add full UI fields with descriptions and predefined values
# * Add default variables to make service call usage easier
# * Improve performance by only calling ZHA device write actions when currently set melody is different than parameter melody
# * Done by using input_text to store last set melody type
#
# SETUP: See instructions at bottom of the script
#
alias: Tuya Siren ZHA
sequence:
- if:
- condition: not
conditions:
- condition: template
value_template: >-
{{ is_state('input_text.' + (melody_entity_id |
default(default_melody_id)), (melody | default(default_melody)))
}}
then:
- service: input_text.set_value
target:
entity_id: input_text.{{(melody_entity_id | default(default_melody_id))}}
data:
value: "{{ melody }}"
- service: zha.set_zigbee_cluster_attribute
data:
ieee: "{{ ieee_id | default(default_ieed) }}"
endpoint_id: 1
cluster_id: 6
cluster_type: in
attribute: 1126
value: "{{ melody | default(default_melody) }}"
- service: zha.set_zigbee_cluster_attribute
data:
ieee: "{{ ieee_id | default(default_ieed) }}"
endpoint_id: 1
cluster_id: 6
cluster_type: in
attribute: 615
value: "{{ duration | default(default_duration) }}"
- service: zha.set_zigbee_cluster_attribute
data:
ieee: "{{ ieee_id | default(default_ieed) }}"
endpoint_id: 1
cluster_id: 6
cluster_type: in
attribute: 1140
value: "{{ volume | default(default_volume) }}"
- service: zha.set_zigbee_cluster_attribute
data:
ieee: "{{ ieee_id | default(default_ieed) }}"
endpoint_id: 1
cluster_id: 6
cluster_type: in
attribute: 0
value: "{{ alarm | default(1) }}"
- service: switch.turn_on
target:
entity_id: switch.{{ (siren_entity_id | default(default_siren_id)) }}
data: {}
description: Tuya Siren ZHA
fields:
ieee_id:
default: a4:c1:38:a0:19:76:33:8b
description: IEEE value found under 'Zigbee Info' on the siren 'Device Info' page in HA
example: a4:c1:38:00:12:34:56:78
selector:
text: null
melody:
default: "0"
description: "Melody that will be played based on ID from https://zigbee.blakadder.com/Neo_NAS-AB02B2.html"
example: 1-18
selector:
select:
mode: dropdown
# https://zigbee.blakadder.com/Neo_NAS-AB02B2.html
options:
- label: Doorbell Chime
value: "0"
- label: Fur Elise
value: "1"
- label: Westminster Chimes
value: "2"
- label: Fast double door bell
value: "3"
- label: William Tell Overture
value: "4"
- label: Turkish March
value: "5"
- label: Safe/Security Alarm
value: "6"
- label: Chemical Spill Alert
value: "7"
- label: Piercing Alarm Clock
value: "8"
- label: Smoke Alarm
value: "9"
- label: Dog Barking
value: "10"
- label: Police Siren
value: "11"
- label: Doorbell Chime (reverb)
value: "12"
- label: Mechanical Telephone
value: "13"
- label: Fire/Ambulance
value: "14"
- label: 3/1 Elevator
value: "15"
- label: Buzzing Alarm Clock
value: "16"
- label: School Bell
value: "17"
duration:
default: 4
description: Duration melody will be played for
selector:
number:
min: 0
max: 100
mode: box
unit_of_measurement: "seconds"
volume:
default: "1"
description: Volume of the melody
selector:
select:
options:
- label: Low
value: "0"
- label: Medium
value: "1"
- label: High
value: "2"
alarm:
default: "on"
description: When writing alarm settings, should alarm be on? Leave as default
example: on or off
selector:
select:
options:
- label: "Off"
value: "off"
- label: "On"
value: "on"
neo_siren_switch:
default: neo_siren_switch
selector:
entity: {}
name: siren_entity_id
description: The switch entity for the siren
neo_melody_text:
default: neo_alarm_melody
description: The text_input helper entity that stores the current melody type
selector:
entity: {}
name: melody_entity_id
variables:
# THESE ARE THE DEFAULTS ACTUALLY USED when using this script through a service call and fields are not set
# the defaults in the fields above ^^ are only used when enabling a field through the UI
#
# Ideally, should set the field defaults above and the variable defaults below to the same value
#
#
# IEEE value found under 'Zigbee Info' on the siren 'Device Info' page in HA
default_ieed: a4:c1:38:a0:19:76:33:8b
# melody ID found at https://zigbee.blakadder.com/Neo_NAS-AB02B2.html
default_melody: 0
default_duration: 4
default_volume: 1
# CREATE AN INPUT HELPER (input_text) and use its entity id here
default_melody_id: neo_alarm_melody
# The entity id of the siren's switch
default_siren_id: neo_siren_switch
mode: parallel
Now replace the following sections with the data you gathered in STEP 1:
- fields → ieee_id → default → IEED ID
- fields → neo_siren_switch → default → Siren Siwtch Entity ID
- fields → neo_melody_text → default → Input Text helper Entity ID
- variables → default_ieed → IEED ID
- variables → default_melody_id → Input Text helper Entity ID
- variables → default_siren_id → Siren Siwtch Entity ID
Then Save Script
STEP 3: Using the script
Congratulations, you can now use the script! Compared to the original script and other examples in this thread you do not need to specify any parameters when calling the script now. However you may stay specify everything/anything if you want.
Using in the UI (in an automation or via service call) you will now have pre-filled fields
Using in YAML mode is the same but you only need to specify melody, volume, and duration (optimally).
