Skip to content

Commit

Permalink
Update to 2024.5.2
Browse files Browse the repository at this point in the history
- deprecate camera.kiosk
- deprecate script.tts_failed
- update mobile weather ui
- media_play bugfix
- entity.split('.')[1] > states[entity].object_id
- refactor mass entity '_2' to expand('group.mass_media_players')...
  • Loading branch information
jazzyisj committed May 7, 2024
1 parent 766c011 commit 232bee4
Show file tree
Hide file tree
Showing 34 changed files with 112 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .HA_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.5.1
2024.5.2
2 changes: 1 addition & 1 deletion automations/alarm/alarm_announcements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
variables:
mode: "{{ state_attr(trigger.entity_id, 'arm_mode') | replace('armed_', '') }}"
current_alarm: "{{ states('input_text.current_alarm') }}"
zone: "{{ trigger.entity_id.split('.')[1] }}"
zone: "{{ states[trigger.entity_id].object_id }}"
trigger:
- platform: state
entity_id: alarm_control_panel.master
Expand Down
4 changes: 2 additions & 2 deletions automations/hass/hass_alert_notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
description: "Send or clear hass alert notifications."
mode: parallel
variables:
tag: "{{ trigger.entity_id.split('.')[1] | replace('_filtered', '') }}"
tag: "{{ states[trigger.entity_id].object_id | replace('_filtered', '') }}"
group: >
{% if trigger.entity_id == 'alert.unavailable_entities' %}
group.unavailable_entities_filtered
{% else %}
group.{{ trigger.entity_id.split('.')[1] }}
group.{{ states[trigger.entity_id].object_id }}
{% endif %}
trigger:
- platform: state
Expand Down
6 changes: 3 additions & 3 deletions automations/light/light_scene_lighting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
variables:
scene: >
{% if trigger.entity_id in ['switch.chill_scene', 'switch.company_scene',
'switch.movie_scene'] %} {{ trigger.entity_id.split('.')[1][:-6] }}
'switch.movie_scene'] %} {{ states[trigger.entity_id].object_id[:-6] }}
{% elif trigger.entity_id == 'binary_sensor.waketime_active' %} morning
{% endif %}
scene_lights: &scene_lights >
Expand Down Expand Up @@ -148,8 +148,8 @@
mode: restart
variables:
scene: >
{{ trigger.entity_id.split('.')[1][4:] if trigger.id =='sensor'
else trigger.entity_id.split('.')[1] }}
{{ states[trigger.entity_id].object_id[4:] if trigger.id =='sensor'
else states[trigger.entity_id].object_id }}
trigger:
- platform: state
id: sensor
Expand Down
2 changes: 1 addition & 1 deletion automations/light/light_timers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
max: 50
variables:
light: >
{% set light = 'light.' ~ trigger.entity_id.split('.')[1] %}
{% set light = 'light.' ~ states[trigger.entity_id].object_id %}
{% if is_state_attr(light, 'rgb_light', 'control') %}
{% set light = light ~ '_rgb' %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion automations/lock/lock_rf_operation_status_update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
description: "Update lock status for RF Operations."
mode: parallel
variables:
lock: "{{ trigger.entity_id.split('.')[1] }}"
lock: "{{ states[trigger.entity_id].object_id }}"
trigger:
- platform: state
entity_id:
Expand Down
2 changes: 1 addition & 1 deletion automations/lock/lock_status_update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
action:
- service: input_text.set_value
target:
entity_id: "input_text.{{ entity_id.split('.')[1] }}_status"
entity_id: "input_text.{{ states[entity_id].object_id }}_status"
data: #BUG RF lock/unlock operation events not firing
value: >
{% if event_label == 'Manual unlock operation' %} Unlocked (Manual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
action:
- service: input_number.set_value
target:
entity_id: "input_number.{{ trigger.entity_id.split('.')[1] }}_current_volume"
entity_id: "input_number.{{ states[trigger.entity_id].object_id }}_current_volume"
data:
value: "{{ volume_level }}"
8 changes: 5 additions & 3 deletions automations/notify/notify_alert_notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
description: "Create persistent notification for alert."
mode: parallel
variables:
alert_id: "{{ trigger.entity_id.split('.')[1] }}"
alert_id: "{{ states[trigger.entity_id].object_id }}"
message: |
{%- set t = trigger.entity_id %}
{%- if t == 'alert.calendar_empty' %}
Expand Down Expand Up @@ -77,6 +77,8 @@
description: "Clear notification when alert is turned off."
mode: parallel
max: 25 # allow for multiple alert state changes at once
variables:
tag: "{{ states[trigger.entity_id].object_id }}"
trigger:
- platform: state
id: mobile
Expand Down Expand Up @@ -168,7 +170,7 @@
data:
message: clear_notification
data:
tag: "{{ trigger.entity_id.split('.')[1] }}"
tag: "{{ tag }}"
continue_on_error: true

- if:
Expand All @@ -177,7 +179,7 @@
then:
- service: persistent_notification.dismiss
data:
notification_id: "{{ trigger.entity_id.split('.')[1] }}"
notification_id: "{{ tag }}"
continue_on_error: true

- service: automation.turn_on
Expand Down
2 changes: 1 addition & 1 deletion automations/notify/notify_led_notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mode: parallel
max: 20
variables:
type: "{{ trigger.entity_id.split('.')[1] | replace('_led_alert', '') }}"
type: "{{ states[trigger.entity_id].object_id | replace('_led_alert', '') }}"
trigger:
- platform: state
entity_id:
Expand Down
2 changes: 1 addition & 1 deletion automations/presence/presence_occupancy_notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
and now() - states.alarm_control_panel.master.last_changed
< timedelta(seconds=run_delay) }}
{% endif %}
zone: "{{ iif(trigger.id in ['armed', 'disarmed'], trigger.entity_id.split('.')[1], 'master') }}"
zone: "{{ iif(trigger.id in ['armed', 'disarmed'], states[trigger.entity_id].object_id, 'master') }}"
trigger:
- platform: state
id: occupancy
Expand Down
2 changes: 1 addition & 1 deletion automations/zwave/zwave_keypress_events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
| map(attribute='entity_id') | join %}
{% endif %}
{{ entity | replace('switch.', 'light.') }}
timer: "{{ 'timer.' ~ entity.split('.')[1] | replace('_rgb', '') if entity != '' else '' }}"
timer: "{{ 'timer.' ~ states[entity].object_id | replace('_rgb', '') if entity != '' else '' }}"
key_value: "{{ trigger.event.data['value'] }}"
key_name: "{{ trigger.event.data['property_key_name'] }}"
trigger:
Expand Down
2 changes: 1 addition & 1 deletion custom_templates/google_home.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{%- endmacro -%}

{%- macro alarm_state(entity) -%}
{%- set switch = 'input_boolean.' ~ entity.split('.')[1] | replace('_alarms', '_alarm_clock_enabled') %}
{%- set switch = 'input_boolean.' ~ states[entity].object_id | replace('_alarms', '_alarm_clock_enabled') %}
{%- set alarms = state_attr(entity, 'alarms') %}
{%- if alarms is iterable and alarms is not mapping and alarms | count > 0 %}
{{- alarms[0].fire_time | timestamp_local | as_datetime if is_state(switch, 'on') else none }}
Expand Down
10 changes: 5 additions & 5 deletions custom_templates/light.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

{%- macro light_timer(light) -%}
{%- if state_attr(light, 'rgb_light') == 'master' %}
{%- set object_id = state_attr(light, 'rgb_control').split('.')[1] | default('') %}
{%- set object_id = states[state_attr(light, 'rgb_control')].object_id | default('') %}
{%- elif state_attr(light, 'rgb_light') == 'slave' %}
{%- set object_id = state_attr(state_attr(light, 'master'), 'rgb_control').split('.')[1] | default('') %}
{%- set object_id = states[state_attr(state_attr(light, 'master'), 'rgb_control')].object_id | default('') %}
{%- else %}
{%- set object_id = light.split('.')[1] | default('') %}
{%- set object_id = states[light].object_id | default('') %}
{%- endif %}
{%- set timer = 'timer.' ~ object_id %}
{{- timer if has_value(timer) else none -}}
Expand All @@ -29,9 +29,9 @@

{%- macro manual_mode(light, switch) -%}
{%- if state_attr(light, 'rgb_light') == 'master' %}
{%- set object_id = 'light.' ~ state_attr(light, 'rgb_control').split('.')[1] | default('') %}
{%- set object_id = 'light.' ~ states[state_attr(light, 'rgb_control')].object_id | default('') %}
{%- elif state_attr(light, 'rgb_light') == 'slave' %}
{%- set object_id = 'light.' ~ state_attr(state_attr(light, 'master'), 'rgb_control').split('.')[1] | default('') %}
{%- set object_id = 'light.' ~ states[state_attr(state_attr(light, 'master'), 'rgb_control')].object_id | default('') %}
{%- endif %}
{{- light in state_attr(switch, 'manual_control')
if switch != none and state_attr(switch, 'manual_control') != none else false -}}
Expand Down
22 changes: 11 additions & 11 deletions custom_templates/media_player.jinja
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{%- macro player_state(entity) -%}
{%- set mass = entity ~ '_2' %}
{%- set sensor = namespace(state='off') %}
{%- set media_types = ['tts', 'alarm_clock'] %}
{%- set group_players = state_attr('group.group_media_players', 'entity_id') %}
{%- if is_state(entity, ['playing', 'paused', 'buffering', 'on', 'idle', 'off'])
or is_state(mass, ['playing', 'paused', 'buffering', 'on', 'idle', 'off']) %}
{%- if is_state(entity, ['playing', 'paused', 'buffering', 'on', 'idle', 'off']) %}
{%- for type in media_types %}
{%- set type_sensor = 'sensor.' ~ type ~ '_active_media_player' %}
{%- set type_player = states(type_sensor) | replace('_2', '') %}
{%- set type_player = states(type_sensor) %}
{%- set type_players = state_attr(type_sensor, 'entity_id') %}
{%- if is_state('binary_sensor.' ~ type, 'on') or is_state('input_boolean.' ~ type, 'on') %}
{%- if has_value(type_sensor) %}
Expand All @@ -22,11 +20,9 @@
{%- endfor %}
{%- if sensor.state == 'off' and group_players != none %}
{%- for player in group_players %}
{%- set mass_player = player ~ '_2' %}
{%- set sensor_players = state_attr('sensor.' ~ player.split('.')[1], 'entity_id') %}
{%- set sensor_players = state_attr('sensor.' ~ states[player].object_id, 'entity_id') %}
{%- if sensor_players != none %}
{%- if entity in sensor_players and (is_state(player, ['playing', 'paused', 'buffering', 'on'])
or is_state(mass_player, ['playing', 'paused', 'buffering', 'on'])) %}
{%- if entity in sensor_players and (is_state(player, ['playing', 'paused', 'buffering', 'on'])) %}
{%- set sensor.state = 'group' %}
{%- break %}
{%- endif %}
Expand Down Expand Up @@ -64,8 +60,10 @@
{%- endmacro -%}

{%- macro player_status(entity) -%}
{%- set state = states('sensor.' ~ entity.split('.')[1]) %}
{%- set mass = entity ~ '_2' %}
{%- set state = states('sensor.' ~ states[entity].object_id) if states[entity] != none else '' %}
{%- set mass = expand('group.mass_media_players')
| selectattr('name', 'eq', state_attr(entity, 'friendly_name'))
| map(attribute='entity_id') | list %}
{%- set mass_players = state_attr('group.mass_media_players','entity_id')
if state_attr('group.mass_media_players','entity_id') != none else [] %}
{%- if mass in mass_players and not is_state(mass, ['off', 'idle', 'standby', 'unknown', 'unavailable']) %}
Expand All @@ -80,7 +78,9 @@
{%- endmacro -%}

{%- macro group_player_status(entity) -%}
{%- set mass = entity ~ '_2' %}
{%- set mass = expand('group.mass_media_players')
| selectattr('name', 'eq', state_attr(entity, 'friendly_name'))
| map(attribute='entity_id') | list %}
{%- set mass_players = state_attr('group.mass_media_players','entity_id')
if state_attr('group.mass_media_players','entity_id') != none else [] %}
{%- if mass in mass_players and not is_state(mass, ['off', 'idle', 'standby', 'unknown', 'unavailable']) %}
Expand Down
2 changes: 1 addition & 1 deletion custom_templates/speech.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The storm is {{ iif(dist > 0,
{%- for item in locks %}
{%- set qty.value = qty.value | int(0) + 1 %}
{%- if not loop.first %}{% set msg.value = msg.value ~ ', ' %}{% endif %}
{%- set msg.value = msg.value ~ item.split('.')[1] | replace('_door_lock', '') | replace('_', ' ') | title %}
{%- set msg.value = msg.value ~ states[item].object_id | replace('_door_lock', '') | replace('_', ' ') | title %}
{%- endfor %}
{%- set clist = ', and ' if msg.value.split(', ') | count > 2 else ' and ' %}
{%- set plural = 's have' if qty.value | int(0) > 1 else ' has' %}
Expand Down
2 changes: 1 addition & 1 deletion custom_templates/style.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- macro alert_switch(entity) -%}
{%- set active_alert = states.alert | selectattr('attributes.category', 'eq', entity.split('.')[1][:-7])
{%- set active_alert = states.alert | selectattr('attributes.category', 'eq', states[entity].object_id[:-7])
| selectattr('state', 'ne', 'idle') | list | count > 0 -%}
:host {
--paper-item-icon-color:
Expand Down
2 changes: 1 addition & 1 deletion packages/scene/shower_scene.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ switch:
entity_id: media_player.bathroom_speaker
volume: >
{% for item in state_attr('group.group_media_players', 'entity_id') %}
{% set sensor = 'sensor.' ~ item.split('.')[1] %}
{% set sensor = 'sensor.' ~ states[item].object_id %}
{% if states(sensor) == 'on'
and 'media_player.bathroom_speaker' in state_attr(sensor, 'entity_id') %}
{{ (state_attr(item, 'volume_level')*100) | int }}
Expand Down
2 changes: 1 addition & 1 deletion scripts/fan/turn_fan_off.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ turn_fan_off:
sequence:
- variables:
timer: >
{% set timer = 'timer.' ~ repeat.item.split('.')[1] | default('') %}
{% set timer = 'timer.' ~ states[repeat.item].object_id | default('') %}
{{ timer if has_value(timer) else none }}
- if:
Expand Down
2 changes: 1 addition & 1 deletion scripts/fan/turn_fan_on.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ turn_fan_on:
sequence:
- variables:
timer: >
{% set timer = 'timer.' ~ repeat.item.split('.')[1] | default('') %}
{% set timer = 'timer.' ~ states[repeat.item].object_id | default('') %}
{{ timer if has_value(timer) else none }}
- if:
Expand Down
8 changes: 4 additions & 4 deletions scripts/media/media_play.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ media_play:
preset_players: >
{% if media_player != '' %}
{% if is_state_attr(media_player, 'type', 'group') %}
{{ state_attr(media_player, 'entity_id') }}
{{ state_attr('sensor.' ~ states[media_player].object_id, 'entity_id') }}
{% else %} {{ media_player }}
{% endif %}
{% else %} {{ none }}
{% endif %}
stop_player: >
{% set stop_player = namespace(entity_id=none) %}
{% if media_player != '' %}
{% set media_sensor = 'sensor.' ~ media_player.split('.')[1] %}
{% set media_sensor = 'sensor.' ~ states[media_player].object_id %}
{% set groups = state_attr('group.group_media_players', 'entity_id') %}
{% if media_player in groups %}
{% set players = state_attr(media_sensor, 'entity_id') %}
{% for group_speaker in groups %}
{% set group_sensor = 'sensor.' ~ group_speaker.split('.')[1] %}
{% set group_sensor = 'sensor.' ~ states[group_speaker].object_id %}
{% if states(group_sensor) == 'on' %} {{ group_sensor }}
{% set group_players = state_attr(group_sensor, 'entity_id') %}
{% for player_item in players %}
Expand All @@ -49,7 +49,7 @@ media_play:
{% endfor %}
{% else %}
{% for group_speaker in groups %}
{% set sensor = 'sensor.' ~ group_speaker.split('.')[1] %}
{% set sensor = 'sensor.' ~ states[group_speaker].object_id %}
{% if media_player in state_attr(sensor, 'entity_id')
and states(group_speaker) not in ['off', 'unknown', 'unavailable'] %}
{% set stop_player.entity_id = group_speaker %}
Expand Down
18 changes: 9 additions & 9 deletions scripts/media/media_player/media_player_save_volumes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ media_player_save_volumes:
sequence:
- variables:
player: "{{ media_players[repeat.index-1] }}"
player_object_id: >
{{ (expand('group.media_players')
player_id: >
{{ states[(expand('group.media_players')
| selectattr('name', 'eq', state_attr(player,'friendly_name'))
| map(attribute='entity_id') | join('')).split('.')[1] }}
| map(attribute='entity_id') | join(''))].object_id }}
# if tts and phone one, use phone vols for tts restore in case phone off before tts
volume_entity: >
{% if source == 'reset' %}
{% if is_state('binary_sensor.mobile_phone_in_use', 'on') %} input_number.{{ player_object_id ~ '_phone' }}
{% else %} input_number.{{ player_object_id ~ '_current_volume' }}
{% if is_state('binary_sensor.mobile_phone_in_use', 'on') %} input_number.{{ player_id ~ '_phone' }}
{% else %} input_number.{{ player_id ~ '_current_volume' }}
{% endif %}
{% else %} input_number.{{ player_object_id ~ '_' ~ source }}
{% else %} input_number.{{ player_id ~ '_' ~ source }}
{% endif %}
# volume default 0.5/0.5 = 1 (no adjustment)
default_volume: >
{% set dv = states('input_number.' ~ player_object_id ~ '_default_volume') | float(-1) %}
{% set dv = states('input_number.' ~ player_id ~ '_default_volume') | float(-1) %}
{{ dv if dv > 0 else 0.5 }}
volume_factor: >
{% if is_state('input_boolean.volume_balancing', 'on') %}
Expand All @@ -62,9 +62,9 @@ media_player_save_volumes:
{% if volume > -1 %}
{{ volume }}
{% elif source == 'tts' and is_state('binary_sensor.mobile_phone_in_use', 'on') %}
{{ states('input_number.' ~ player_object_id ~ '_phone') | float(-1) }}
{{ states('input_number.' ~ player_id ~ '_phone') | float(-1) }}
{% else %}
{{ states('input_number.' ~ player_object_id ~ '_current_volume') | float(-1) }}
{{ states('input_number.' ~ player_id ~ '_current_volume') | float(-1) }}
{% endif %}
quiet_volume: >
{% set qv = (states('input_number.speaker_quiet_volume') | int/100) | float(-1) %}
Expand Down
8 changes: 4 additions & 4 deletions scripts/media/media_player/media_player_set_volumes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ media_player_set_volumes:
sequence:
- variables:
player: "{{ media_players[repeat.index-1] }}"
player_name: "{{ player.split('.')[1] }}"
player_id: "{{ states[player].object_id }}"
source_volume: >
{% if source_off %} {{ states('input_number.' ~ player_name ~ '_' ~ source[0:-4]) | float(-1) }}
{% if source_off %} {{ states('input_number.' ~ player_id ~ '_' ~ source[0:-4]) | float(-1) }}
{% else %} -1
{% endif %}
- if:
Expand All @@ -115,8 +115,8 @@ media_player_set_volumes:
if is_state_attr(player, 'device_class', 'tv') else true }}
then:
- variables:
current_volume: "{{ states('input_number.' ~ player_name ~ '_current_volume') | float(-1) }}"
default_volume: "{{ states('input_number.' ~ player_name ~ '_default_volume') | float(-1) }}"
current_volume: "{{ states('input_number.' ~ player_id ~ '_current_volume') | float(-1) }}"
default_volume: "{{ states('input_number.' ~ player_id ~ '_default_volume') | float(-1) }}"
volume_factor: >
{% if default_volume > 0 and is_state('input_boolean.volume_balancing', 'on') %}
{{ 1/(0.5/default_volume) ** states('input_number.volume_log_factor') | float }}
Expand Down
2 changes: 1 addition & 1 deletion scripts/media/media_player/turn_media_player_on.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ turn_media_player_on:
{% for player in media_players %}
{% if is_state_attr(player, 'type', 'group') %}
{% set groups.entity_id = groups.entity_id
+ state_attr('sensor.' ~ player.split('.')[1], 'entity_id') %}
+ state_attr('sensor.' ~ states[player].object_id, 'entity_id') %}
{% endif %}
{% endfor %}
{{ groups.entity_id }}
Expand Down
Loading

0 comments on commit 232bee4

Please sign in to comment.