AutomationDataset/tjuuljensen/description-ready.json

502 lines
54 KiB
JSON

[
{
"id": "'Battery Alert: Notification'",
"automation": "- alias: 'Battery Alert: Notification'\n description: This is a combined battery Alert Notification automation. Based on\n the value of input_select.notifier_format the notification is delivered using\n the notify integration or as a persistent notification. Notifications using the\n Default notification are automatically dismissed after 15 minutes. Persistent\n notification will be cleared every 15th minute if the sensor alerts are cleared.\n triggers:\n - at: input_datetime.low_battery_notification_check\n trigger: time\n id: time\n - entity_id:\n - input_number.battery_alert_threshold_min\n - input_number.battery_alert_threshold_max\n trigger: state\n id: threshold_changed\n - minutes: /15\n seconds: 0\n trigger: time_pattern\n id: every_15_minutes\n - trigger: state\n entity_id:\n - input_select.notifier_format\n id: notifier_format_changed\n - trigger: state\n entity_id:\n - input_boolean.low_batteries\n enabled: true\n id: low_batteries_boolean_changed\n conditions:\n - condition: or\n conditions:\n - alias: If Notifier Format is Persistent then trigger must either be theshold\n or 15 min trigger or notifier format changed\n condition: and\n conditions:\n - condition: state\n entity_id: input_select.notifier_format\n state: Persistent\n - condition: trigger\n id:\n - every_15_minutes\n - threshold_changed\n - notifier_format_changed\n - condition: and\n conditions:\n - condition: not\n conditions:\n - condition: state\n entity_id: input_select.notifier_format\n state: Persistent\n - condition: not\n conditions:\n - condition: trigger\n id:\n - every_15_minutes\n alias: If Notifier Format is Default or Slack do not allow 15 min triggering\n - alias: If Low Batteries is on and trigger is every 15 minutes\n condition: and\n conditions:\n - condition: trigger\n id:\n - every_15_minutes\n - condition: state\n entity_id: input_boolean.low_batteries\n state: 'on'\n enabled: true\n - condition: and\n conditions:\n - condition: trigger\n id:\n - low_batteries_boolean_changed\n - condition: and\n conditions:\n - condition: template\n value_template: '{{ trigger.to_state.context.parent_id == none }}'\n - condition: template\n value_template: '{{ trigger.to_state.context.user_id != none }}'\n - condition: template\n value_template: '{{ trigger.to_state.context.id != none }}'\n alias: If the state change was likely caused by a UI interaction\n alias: If Low Batteries boolean was changed from the UI\n enabled: true\n actions:\n - variables:\n notification_tag: low_battery_alert\n low_batteries: \"{% macro battery_level() %} {% for entity_id in states.group.battery_status.attributes.entity_id\\\n \\ if (\\n not (\\n is_state_attr(entity_id, 'battery_alert_disabled',\\\n \\ true)\\n or is_state_attr(entity_id, 'restored', true)\\n )\\n\\\n \\ and states(entity_id) is not none\\n and (\\n (\\n (\\n states(entity_id)\\\n \\ is number\\n or states(entity_id) | length == states(entity_id)| int(0)\\\n \\ | string | length\\n or states(entity_id) | length == states(entity_id)|\\\n \\ float(0) | string | length\\n )\\n and states(entity_id) | int(0)\\\n \\ <= states('input_number.battery_alert_threshold_max') | int(0)\\n and\\\n \\ states(entity_id) | int(0) >= states('input_number.battery_alert_threshold_min')\\\n \\ | int(0)\\n )\\n or states(entity_id) | lower == 'low'\\n or (states('input_number.battery_alert_threshold_min')\\\n \\ | int(0) == -1 \\n and (states(entity_id) | lower == 'unknown'\\n \\\n \\ or states(entity_id) | lower == 'unavailable'))\\n )\\n ) -%}\\n{{\\\n \\ state_attr(entity_id, \\\"friendly_name\\\") }} ({{ states(entity_id) }}) {%\\\n \\ endfor -%} {% endmacro %} {{ battery_level() | trim != \\\"\\\" }}\\n\"\n notifier: '{{ iif(''notify.'' in states(''input_text.notifier_name''), states(''input_text.notifier_name''),\n ''notify.notify'') }}'\n enabled: true\n - alias: Conditionally clear notifications before progressing\n if:\n - condition: or\n conditions:\n - condition: and\n conditions:\n - condition: state\n entity_id: input_boolean.low_batteries\n state: 'on'\n - condition: template\n value_template: '{{ not low_batteries}}'\n alias: No batteries are currently within threshold\n alias: Low battery bool do not match current low batteries variable\n - condition: trigger\n id:\n - notifier_format_changed\n - threshold_changed\n then:\n - alias: Clear Persistent or Default notifications\n choose:\n - conditions:\n - condition: or\n conditions:\n - alias: Trigger is NOT notifier_format_changed and Notifier Format is Default\n condition: template\n value_template: '{{ trigger.id != \"notifier_format_changed\" and is_state(''input_select.notifier_format'',''Default'')\n }}'\n - alias: Trigger is notifier_format_changed and from state was Default\n condition: template\n value_template: '{{ trigger.id == \"notifier_format_changed\" and trigger.from_state.state\n == \"Default\" }}'\n alias: Test if Default notifications should be cleared\n sequence:\n - alias: Clear Notification\n action: '{{ notifier }}'\n data:\n message: clear_notification\n data:\n tag: '{{ notification_tag }}'\n - conditions:\n - condition: or\n conditions:\n - alias: Trigger is NOT notifier_format_changed and Notifier Format is Persistent\n condition: template\n value_template: '{{ trigger.id != \"notifier_format_changed\" and is_state(''input_select.notifier_format'',''Persistent'')\n }}'\n - alias: Trigger is notifier_format_changed and from state is Persistent\n condition: template\n value_template: '{{ trigger.id == \"notifier_format_changed\" and trigger.from_state.state\n == \"Persistent\" }}'\n alias: Test if Persistent notifications should be cleared\n sequence:\n - action: persistent_notification.dismiss\n metadata: {}\n data:\n notification_id: '{{ notification_tag }}'\n - alias: Send message if there are batteries within threshold\n if:\n - alias: Test if Low Batteries is true (meaning that one or more battery sensors\n have values in the threshold interval )\n condition: template\n value_template: '{{ low_batteries }}\n\n '\n then:\n - variables:\n message_text: \"{% macro battery_level() %} {% for entity_id in \\nstates.group.battery_status.attributes.entity_id\\\n \\ if (\\n not (\\n is_state_attr(entity_id, 'battery_alert_disabled',\\\n \\ true)\\n or is_state_attr(entity_id, 'restored', true)\\n )\\n\\\n \\ and states(entity_id) is not none\\n and (\\n (\\n (\\n states(entity_id)\\\n \\ is number\\n or states(entity_id) | length == states(entity_id)|\\\n \\ int(0) | string | length\\n or states(entity_id) | length == states(entity_id)|\\\n \\ float(0) | string | length\\n )\\n and states(entity_id) | int(0)\\\n \\ <= states('input_number.battery_alert_threshold_max') | int(0)\\n \\\n \\ and states(entity_id) | int(0) >= states('input_number.battery_alert_threshold_min')\\\n \\ | int(0)\\n )\\n or states(entity_id) | lower == 'low'\\n or (states('input_number.battery_alert_threshold_min')\\\n \\ | int(0) == -1 \\n and (states(entity_id) | lower == 'unknown'\\n\\\n \\ or states(entity_id) | lower == 'unavailable'))\\n )\\n) -%}\\n \\\n \\ {{ state_attr(entity_id, \\\"friendly_name\\\") }} ({{ states(entity_id) }})\\n\\\n {% endfor -%} {% endmacro %} {{ battery_level() }}\\n\"\n delay_timer: 900\n - choose:\n - conditions:\n - condition: state\n entity_id: input_select.notifier_format\n state: Default\n - condition: trigger\n id:\n - threshold_changed\n - time\n - notifier_format_changed\n sequence:\n - action: '{{ notifier }}'\n data:\n title: Low Battery Levels\n message: '{{ message_text }}'\n data:\n group: battery\n tag: '{{ notification_tag }}'\n - alias: Wait for time defined in variable delay_timer\n delay: '{{ delay_timer }}'\n - alias: Clear Notification\n action: '{{ notifier }}'\n data:\n message: clear_notification\n data:\n tag: '{{ notification_tag }}'\n - conditions:\n - condition: state\n entity_id: input_select.notifier_format\n state: Slack\n - condition: trigger\n id:\n - threshold_changed\n - time\n - notifier_format_changed\n sequence:\n - action: '{{ notifier }}'\n data:\n message: Low Battery Levels\n data:\n attachments:\n - color: '#52c0f2'\n title: These devices have low battery levels\n text: '{{ message_text }}'\n - conditions:\n - condition: state\n entity_id: input_select.notifier_format\n state: Persistent\n - condition: trigger\n id:\n - every_15_minutes\n - threshold_changed\n - notifier_format_changed\n sequence:\n - action: persistent_notification.create\n metadata: {}\n data:\n title: Low Battery Levels\n notification_id: '{{ notification_tag }}'\n message: '{{ message_text }}'\n - alias: Set Low Battery boolean to the correct state\n if:\n - alias: Test if Low Batteries is true (meaning that one or more battery sensors\n have values in the threshold interval )\n condition: template\n value_template: '{{ low_batteries }}\n\n '\n then:\n - if:\n - condition: state\n entity_id: input_boolean.low_batteries\n state: 'off'\n then:\n - action: input_boolean.turn_on\n metadata: {}\n data: {}\n target:\n entity_id: input_boolean.low_batteries\n alias: If Low Batteries bool is off turn it on\n else:\n - alias: If Low Batteries bool is on turn it off\n if:\n - condition: state\n entity_id: input_boolean.low_batteries\n state: 'on'\n then:\n - action: input_boolean.turn_off\n metadata: {}\n data: {}\n target:\n entity_id: input_boolean.low_batteries\n mode: restart\n initial_state: true",
"config": [
{
"name": "low battery notification check",
"room": null,
"type": "input_datetime",
"id": {
"entity_id": "input_datetime.low_battery_notification_check",
"device_id": null
}
},
{
"name": "battery alert threshold min",
"room": null,
"type": "input_number",
"id": {
"entity_id": "input_number.battery_alert_threshold_min",
"device_id": null
}
},
{
"name": "battery alert threshold max",
"room": null,
"type": "input_number",
"id": {
"entity_id": "input_number.battery_alert_threshold_max",
"device_id": null
}
},
{
"name": "notifier format",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.notifier_format",
"device_id": null
}
},
{
"name": "low batteries",
"room": null,
"type": "input_boolean",
"id": {
"entity_id": "input_boolean.low_batteries",
"device_id": null
}
},
{
"name": "battery status",
"room": null,
"type": "group",
"id": {
"entity_id": "group.battery_status",
"device_id": null
}
},
{
"name": "notifier name",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.notifier_name",
"device_id": null
}
}
]
},
{
"id": "'Battery Alert: Create Sensor From Attributes'",
"automation": "- alias: 'Battery Alert: Create Sensor From Attributes'\n description: This automation creates battery sensors based on other sensor who has\n battery data in their attributes. Sensors can be excluded from this automation\n by defining a 'battery_sensor_creation_disabled' attribute in the customize configuration.\n trigger:\n - platform: event\n event_type: state_changed\n condition:\n - condition: template\n value_template: '{{ trigger is not none }}'\n - condition: template\n value_template: '{{ trigger.event.data is not none }}'\n - condition: template\n value_template: '{{ trigger.event.data.old_state is not none }}'\n - condition: template\n value_template: '{{ trigger.event.data.new_state is not none }}'\n - condition: template\n value_template: '{{ ''battery'' not in trigger.event.data.new_state.name | lower\n }}'\n - condition: template\n value_template: '{{ not is_state_attr(trigger.event.data.entity_id, ''device_class'',\n ''battery'') }}'\n - condition: template\n value_template: '{{ not is_state_attr(trigger.event.data.entity_id, ''battery_sensor_creation_disabled'',\n true) }}'\n - condition: template\n value_template: '{{ not is_state_attr(trigger.event.data.entity_id, ''restored'',\n true) }}'\n - condition: or\n conditions:\n - condition: and\n conditions:\n - condition: template\n value_template: '{{ trigger.event.data.new_state.attributes.battery_level\n is defined }}'\n - condition: template\n value_template: '{{ trigger.event.data.new_state.attributes.battery_level\n is not none }}'\n - condition: and\n conditions:\n - condition: template\n value_template: '{{ trigger.event.data.new_state.attributes.battery is defined\n }}'\n - condition: template\n value_template: '{{ trigger.event.data.new_state.attributes.battery is not\n none }}'\n - condition: and\n conditions:\n - condition: template\n value_template: '{{ trigger.event.data.new_state.attributes.battery_critical\n is defined }}'\n - condition: template\n value_template: '{{ trigger.event.data.new_state.attributes.battery_critical\n is not none }}'\n actions:\n - action: mqtt.publish\n data_template:\n topic: homeassistant/sensor/{{ trigger.event.data.entity_id.split('.')[1] }}_battery/config\n retain: true\n payload: \"{\\n {% if trigger.event.data.new_state.attributes.battery_level is\\\n \\ defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery_level\\\n \\ -%}\\n {%- set attribname = 'battery_level' -%}\\n {%- elif trigger.event.data.new_state.attributes.battery\\\n \\ is defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery\\\n \\ -%}\\n {%- set attribname = 'battery' -%}\\n {% elif trigger.event.data.new_state.attributes.battery_critical\\\n \\ is defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery_critical\\\n \\ -%}\\n {%- set attribname = 'battery_critical' -%}\\n {%- endif -%}\\n\\\n \\ \\\"name\\\": \\\"{{ trigger.event.data.new_state.name }} Battery\\\",\\n \\\"state_topic\\\"\\\n : \\\"homeassistant/sensor/{{ trigger.event.data.entity_id.split('.')[1] }}_battery/state\\\"\\\n ,\\n {% if trigger.event.data.new_state.attributes.battery_template is defined\\\n \\ -%}\\n \\\"value_template\\\": \\\"{{ trigger.event.data.new_state.attributes.battery_template\\\n \\ }}\\\",\\n \\\"unit_of_measurement\\\": \\\"%\\\",\\n \\\"device_class\\\": \\\"battery\\\"\\\n ,\\n {% elif trigger.event.data.new_state.attributes.battery_template_string\\\n \\ is defined -%}\\n \\\"value_template\\\": \\\"{{ trigger.event.data.new_state.attributes.battery_template_string\\\n \\ }}\\\",\\n \\\"icon\\\": \\\"mdi:battery\\\",\\n {% elif trigger.event.data.new_state.attributes.battery_critical\\\n \\ is defined -%}\\n \\\"value_template\\\": \\\"{{ \\\"{{\\\" }} 'low' if value_json.value\\\n \\ else 'full' {{ \\\"}}\\\" }}\\\",\\n \\\"icon\\\": \\\"mdi:battery\\\",\\n {% else -%}\\n\\\n \\ \\\"value_template\\\": \\\"{{ \\\"{{\\\" }} value_json.value | int(0) {{ \\\"}}\\\"\\\n \\ }}\\\",\\n {% if attribval | int(0) == attribval or attribval | float(0)\\\n \\ == attribval or attribval | length == attribval | float(0) | string | length\\\n \\ or attribval | length == attribval | int(0) | string | length -%}\\n \\\"\\\n unit_of_measurement\\\": \\\"%\\\",\\n \\\"device_class\\\": \\\"battery\\\",\\n {%- elif\\\n \\ attribval == \\\"High\\\" or attribval == \\\"Full\\\" -%}\\n \\\"icon\\\": \\\"mdi:battery\\\"\\\n ,\\n {%- elif attribval == \\\"Medium\\\" or attribval == \\\"Med\\\"-%}\\n \\\"icon\\\"\\\n : \\\"mdi:battery-50\\\",\\n {%- elif attribval == \\\"Low\\\" -%}\\n \\\"icon\\\": \\\"\\\n mdi:battery-alert\\\",\\n {%- else -%}\\n \\\"icon\\\": \\\"mdi:battery-unknown\\\"\\\n ,\\n {%- endif %}\\n {% endif -%}\\n \\\"unique_id\\\": \\\"{{ trigger.event.data.entity_id.split('.')[1]\\\n \\ }}_battery\\\",\\n \\\"json_attributes_topic\\\": \\\"homeassistant/sensor/{{ trigger.event.data.entity_id.split('.')[1]\\\n \\ }}_battery/attributes\\\"\\n}\"\n - action: mqtt.publish\n data_template:\n topic: homeassistant/sensor/{{ trigger.event.data.entity_id.split('.')[1] }}_battery/state\n retain: true\n payload: \"{\\n {% if trigger.event.data.new_state.attributes.battery_level is\\\n \\ defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery_level\\\n \\ -%}\\n {%- elif trigger.event.data.new_state.attributes.battery is defined\\\n \\ -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery\\\n \\ -%}\\n {%- elif trigger.event.data.new_state.attributes.battery_critical\\\n \\ is defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery_critical\\\n \\ -%}\\n {%- endif -%}\\n \\\"value\\\": {% if attribval | int(0) == attribval\\\n \\ -%}\\n {{ attribval | int(0) }}\\n {%- elif attribval | float(0) == attribval\\\n \\ -%}\\n {{ attribval | float(0) }}\\n {%- elif attribval | length == attribval\\\n \\ | float(0) | string | length -%}\\n {{ attribval | float(0) }}\\n {%-\\\n \\ elif attribval | length == attribval | int(0) | string | length -%}\\n \\\n \\ {{ attribval | int(0) }}\\n {%- else -%}\\n \\\"{{ attribval }}\\\"\\n \\\n \\ {%- endif %}\\n}\"\n - action: mqtt.publish\n data_template:\n topic: homeassistant/sensor/{{ trigger.event.data.entity_id.split('.')[1] }}_battery/attributes\n retain: true\n payload: \"{\\n {% if trigger.event.data.new_state.attributes.battery_level is\\\n \\ defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery_level\\\n \\ -%}\\n {%- set attribname = 'battery_level' -%}\\n {%- elif trigger.event.data.new_state.attributes.battery\\\n \\ is defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery\\\n \\ -%}\\n {%- set attribname = 'battery' -%}\\n {%- elif trigger.event.data.new_state.attributes.battery_critical\\\n \\ is defined -%}\\n {%- set attribval = trigger.event.data.new_state.attributes.battery_critical\\\n \\ -%}\\n {%- set attribname = 'battery_critical' -%}\\n {%- endif -%}\\n\\\n \\ \\\"entity_id\\\": \\\"{{ trigger.event.data.entity_id }}\\\",\\n {% if attribname\\\n \\ is defined -%}\\n \\\"{{ attribname }}\\\": \\\"{{ attribval }}\\\",\\n {%- endif\\\n \\ %}\\n \\\"delete_battery_sensor\\\": \\\"homeassistant/sensor/{{ trigger.event.data.entity_id.split('.')[1]\\\n \\ }}_battery\\\"\\n}\"",
"config": []
},
{
"id": "'Battery Alert: Update Status Group Members'",
"automation": "- alias: 'Battery Alert: Update Status Group Members'\n description: Updates the group.battery_status each minute with all known battery\n sensors\n initial_state: true\n triggers:\n - trigger: time_pattern\n minutes: /1\n - trigger: state\n entity_id:\n - automation.battery_alert_update_status_group_members\n to: 'on'\n for:\n seconds: 1\n actions:\n - action: group.set\n data_template:\n object_id: battery_status\n entities: \"{% for item in states.sensor if (\\n not is_state_attr(item.entity_id,\\\n \\ 'hidden', true)\\n and (\\n is_state_attr(item.entity_id, 'device_class',\\\n \\ 'battery')\\n or (item.entity_id | lower).endswith('_battery')\\n or\\\n \\ (item.name | lower).endswith('_battery')\\n ) \\n )\\n-%}\\n {{ item.entity_id\\\n \\ }}{% if not loop.last %}, {% endif %}\\n{%- endfor -%}\"",
"config": [
{
"name": "battery status",
"room": null,
"type": "group",
"id": {
"entity_id": "group.battery_status",
"device_id": null
}
},
{
"name": "battery alert update status group members",
"room": null,
"type": "automation",
"id": {
"entity_id": "automation.battery_alert_update_status_group_members",
"device_id": null
}
}
]
},
{
"id": "'Battery Alert: Delete a Sensor'",
"automation": "- alias: 'Battery Alert: Delete a Sensor'\n description: 'Enables the deletion of battery sensors created using MQTT in the\n ''Battery Alert: Create Sensor From Attributes'' automation. enter the name of\n the sensor in input_text.delete_battery_sensor in either MQTT format (homeassistant/sensor/foo)\n or in normal homeassistant notation (sensor.foo).'\n triggers:\n - entity_id:\n - input_text.delete_battery_sensor\n trigger: state\n conditions:\n - condition: template\n value_template: '{{ ''homeassistant/sensor/'' in states(''input_text.delete_battery_sensor'')\n or ''sensor.'' in states(''input_text.delete_battery_sensor'')[0:7] }}'\n alias: 'If mqtt format or default homeassistant notation is used '\n actions:\n - variables:\n sensor_to_delete: '{% set sensor_name = states(''input_text.delete_battery_sensor'')\n %}\n\n {{ iif(''sensor.'' in sensor_name[0:7] , ''homeassistant/''+sensor_name.replace(''.'',''/''),sensor_name)\n }}\n\n '\n alias: Define vaiable to hold mqtt sensor name\n - data_template:\n topic: '{{ sensor_to_delete }}'\n retain: true\n action: mqtt.publish\n - data_template:\n topic: '{{ sensor_to_delete }}/attributes'\n retain: true\n action: mqtt.publish\n - data_template:\n topic: '{{ sensor_to_delete }}/state'\n retain: true\n action: mqtt.publish\n - data_template:\n topic: '{{ sensor_to_delete }}/config'\n retain: true\n action: mqtt.publish\n - action: input_text.set_value\n metadata: {}\n data:\n value: '# MQTT delete message sent #'\n target:\n entity_id: input_text.delete_battery_sensor\n - delay:\n hours: 0\n minutes: 0\n seconds: 2\n milliseconds: 0\n - action: input_text.set_value\n metadata: {}\n data:\n value: ''\n target:\n entity_id: input_text.delete_battery_sensor",
"config": [
{
"name": "delete battery sensor",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.delete_battery_sensor",
"device_id": null
}
}
]
},
{
"id": "livetrack_initialize",
"automation": "- alias: 'Livetrack: Initialize Values at Homeassistant Start'\n id: livetrack_initialize\n description: Will run at HA start. Only need to run once. Can be disabled afterwards\n trigger:\n - trigger: homeassistant\n event: start\n conditions:\n - condition: or\n conditions:\n - condition: state\n entity_id: input_text.livetrack_notifier_name\n state: ''\n - condition: state\n entity_id: input_text.livetrack_local_json_path\n state: ''\n actions:\n - choose:\n - conditions:\n - condition: state\n entity_id: input_text.livetrack_local_json_path\n state: ''\n sequence:\n - action: input_text.set_value\n data:\n value: https://homeassistant.local:8123/local/livetrack/empty_garmin.json\n target:\n entity_id: input_text.livetrack_local_json_path\n - conditions:\n - condition: state\n entity_id: input_text.livetrack_notifier_name\n state: ''\n sequence:\n - stop: Stopping automation. No further values set.\n - action: input_text.set_value\n data:\n value: notify.notify\n target:\n entity_id: input_text.livetrack_notifier_name\n - action: shell_command.create_empty_garmin_json_file\n data: {}",
"config": [
{
"name": "livetrack notifier name",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.livetrack_notifier_name",
"device_id": null
}
},
{
"name": "livetrack local json path",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.livetrack_local_json_path",
"device_id": null
}
}
]
},
{
"id": "'Hue motion sensor: Multihub fetch data when input selects change'",
"automation": "- alias: 'Hue motion sensor: Multihub fetch data when input selects change'\n description: Update Value when input select changes\n triggers:\n - trigger: state\n entity_id:\n - input_select.hue_hubs\n id: hub_change\n - trigger: template\n value_template: '{{ is_state(''sensor.hue_motion_sensor_hub_data'',''unknown'')\n }}'\n alias: When hub identifier number is unknown\n id: hub_identifier_unknown\n - trigger: state\n entity_id:\n - input_select.hue_hubs\n from: Undefined\n id: after_start\n condition: []\n actions:\n - choose:\n - conditions:\n - condition: trigger\n id:\n - hub_change\n sequence:\n - choose:\n - conditions:\n - condition: template\n value_template: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[0].name\n == states(''input_select.hue_hubs'') }}'\n sequence:\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[0].ip\n }}'\n target:\n entity_id: input_text.hue_hub_ip\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[0].user\n }}'\n target:\n entity_id: input_text.hue_hub_username\n - conditions:\n - condition: template\n value_template: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[1].name\n == states(''input_select.hue_hubs'') }}'\n sequence:\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[1].ip\n }}'\n target:\n entity_id: input_text.hue_hub_ip\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[1].user\n }}'\n target:\n entity_id: input_text.hue_hub_username\n alias: Update Hub IP and username\n - conditions:\n - condition: trigger\n id:\n - hub_identifier_unknown\n - after_start\n sequence:\n - repeat:\n count: '{{ (state_attr(''input_select.hue_hubs'',''options'') | length)-1\n }}'\n sequence:\n - action: input_select.select_next\n data:\n cycle: true\n target:\n entity_id: input_select.hue_hubs\n - choose:\n - conditions:\n - condition: template\n value_template: '{{ (states(''input_text.hue_hubs'',''options'') |\n from_json)[0].name == states(''input_select.hue_hubs'') }}'\n sequence:\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[0].ip\n }}'\n target:\n entity_id: input_text.hue_hub_ip\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[0].user\n }}'\n target:\n entity_id: input_text.hue_hub_username\n - conditions:\n - condition: template\n value_template: '{{ (states(''input_text.hue_hubs'',''options'') |\n from_json)[1].name == states(''input_select.hue_hubs'') }}'\n sequence:\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[1].ip\n }}'\n target:\n entity_id: input_text.hue_hub_ip\n - action: input_text.set_value\n data:\n value: '{{ (states(''input_text.hue_hubs'',''options'') | from_json)[1].user\n }}'\n target:\n entity_id: input_text.hue_hub_username\n alias: Update Hub IP and username\n enabled: true\n - action: homeassistant.update_entity\n data: {}\n target:\n entity_id: sensor.hue_motion_sensor_hub_data\n alias: Get hub data for the selected sensor\n enabled: true\n - wait_template: '{{ not is_state(''sensor.hue_motion_sensor_hub_data'',''unknown'')\n }}'\n continue_on_timeout: true\n alias: Wait for sensor sensitivity to change or on timeout\n timeout: 00:00:05\n enabled: true\n - if:\n - condition: template\n value_template: '{{ state_attr(''input_select.hue_motion_sensitivity'',''options'')[int(state_attr(''sensor.hue_motion_sensor_hub_data'',''sensitivity''),0)]\n != states(''input_select.hue_motion_sensitivity'') }}'\n alias: Selected sensitivity in UI differs from sensor sensitivity\n then:\n - action: input_select.select_option\n data:\n option: '{{ state_attr(''input_select.hue_motion_sensitivity'',''options'')[int(state_attr(''sensor.hue_motion_sensor_hub_data'',''sensitivity''),0)]\n }}'\n target:\n entity_id: input_select.hue_motion_sensitivity\n alias: Set sensitivity input select to actual configured value\n - stop: Hub data found on other hub\n mode: parallel\n max: 10",
"config": [
{
"name": "hue hubs",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.hue_hubs",
"device_id": null
}
},
{
"name": "hue motion sensor hub data",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.hue_motion_sensor_hub_data",
"device_id": null
}
},
{
"name": "hue hub ip",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.hue_hub_ip",
"device_id": null
}
},
{
"name": "hue hub username",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.hue_hub_username",
"device_id": null
}
},
{
"name": "hue motion sensitivity",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.hue_motion_sensitivity",
"device_id": null
}
},
{
"name": "Hue Hubs",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.hue_hubs",
"device_id": null
}
}
]
},
{
"id": "'Hue motion sensor: Fill input selects with data'",
"automation": "- alias: 'Hue motion sensor: Fill input selects with data'\n description: Based on the attribute sensitivitymax, the sensitivity selector has\n 3 or 5 levels to choose from\n triggers:\n - trigger: template\n value_template: '{{ state_attr(''sensor.hue_motion_sensor_hub_data'',''sensitivitymax'')==2\n }}'\n id: sensitivity_basic\n alias: When sensitivity of sensor is basic (three levels)\n - trigger: template\n value_template: '{{ state_attr(''sensor.hue_motion_sensor_hub_data'',''sensitivitymax'')==4\n }}'\n id: sensitivity_advanced\n alias: When sensitivity of sensor is advanced (five levels)\n - trigger: homeassistant\n event: start\n id: start\n - trigger: event\n id: reload\n event_type: event_template_reloaded\n condition: []\n actions:\n - choose:\n - conditions:\n - condition: trigger\n id: sensitivity_basic\n sequence:\n - action: input_select.set_options\n data:\n options:\n - Low\n - Medium\n - High\n target:\n entity_id: input_select.hue_motion_sensitivity\n - conditions:\n - condition: trigger\n id: sensitivity_advanced\n sequence:\n - action: input_select.set_options\n data:\n options:\n - Very low\n - Low\n - Medium\n - High\n - Very high\n target:\n entity_id: input_select.hue_motion_sensitivity\n - conditions:\n - condition: trigger\n id: start\n sequence:\n - action: input_select.set_options\n data:\n options: '{{ states.binary_sensor | selectattr(''attributes.device_class'',\n ''defined'') | selectattr(''attributes.device_class'',''eq'',''motion'')\n | selectattr(''state'',''ne'',''unavailable'') | rejectattr(''attributes.entity_id'',\n ''defined'') | rejectattr(''attributes.type'', ''defined'') | map(attribute=''entity_id'')\n | list }}'\n target:\n entity_id: input_select.motion_sensor_entities\n alias: Use Service to add all Hue motion sensors to input select\n - action: input_select.set_options\n data:\n options: '{{ states(''input_text.hue_hubs'') | from_json | map(attribute=''name'')\n | list }}'\n target:\n entity_id: input_select.hue_hubs\n alias: Update hubs in hue hub input select\n - action: input_select.select_option\n data:\n option: '{{ state_attr(''input_select.hue_motion_sensitivity'',''options'')[int(state_attr(''sensor.hue_motion_sensor_hub_data'',''sensitivity''),0)]\n }}'\n target:\n entity_id: input_select.hue_motion_sensitivity\n alias: Set sensitivity input select to match motion sensor value\n enabled: true\n mode: single",
"config": [
{
"name": "hue hubs",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.hue_hubs",
"device_id": null
}
},
{
"name": "hue motion sensor hub data",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.hue_motion_sensor_hub_data",
"device_id": null
}
},
{
"name": "hue motion sensitivity",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.hue_motion_sensitivity",
"device_id": null
}
},
{
"name": "motion sensor entities",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.motion_sensor_entities",
"device_id": null
}
},
{
"name": "Hue Hubs",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.hue_hubs",
"device_id": null
}
}
]
},
{
"id": "'Hue motion sensor: Refresh data when selected sensor changes'",
"automation": "- alias: 'Hue motion sensor: Refresh data when selected sensor changes'\n description: Update value when input select changes\n triggers:\n - trigger: state\n entity_id:\n - input_select.motion_sensor_entities\n id: entity_updated\n condition: []\n actions:\n - choose:\n - conditions:\n - condition: trigger\n id:\n - entity_updated\n sequence:\n - action: homeassistant.update_entity\n data: {}\n target:\n entity_id: sensor.hue_motion_sensor_hub_data\n alias: Get hub data for the selected sensor\n - action: input_select.select_option\n data:\n option: '{{ state_attr(''input_select.hue_motion_sensitivity'',''options'')[int(state_attr(''sensor.hue_motion_sensor_hub_data'',''sensitivity''),0)]\n }}'\n target:\n entity_id: input_select.hue_motion_sensitivity\n alias: Set sensitivity input select to actual configured value\n mode: parallel\n max: 10",
"config": [
{
"name": "hue motion sensor hub data",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.hue_motion_sensor_hub_data",
"device_id": null
}
},
{
"name": "hue motion sensitivity",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.hue_motion_sensitivity",
"device_id": null
}
},
{
"name": "motion sensor entities",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.motion_sensor_entities",
"device_id": null
}
}
]
},
{
"id": "pollen_trigger_update_of_pollen_sensors",
"automation": "- alias: 'Pollen: Trigger update of pollen sensors'\n id: pollen_trigger_update_of_pollen_sensors\n description: If pollen sensors are not updated today, try to update every 30 mins\n during the afternoon\n triggers:\n - trigger: time\n at: '16:00:00'\n id: pre_season_single_time_trigger\n - trigger: time_pattern\n minutes: /30\n id: in_season_recurring_time_trigger\n - trigger: state\n entity_id:\n - input_button.pollen_update_feed\n id: button_trigger\n conditions:\n - condition: or\n conditions:\n - alias: If in pre season and pollen is not in the air\n condition: and\n conditions:\n - condition: template\n value_template: '{{ states(''sensor.pollen_update_time'') | as_timestamp()\n < states(''sensor.pollen_timestamp_start_of_today'') | float(0) }}'\n alias: If Pollen sensors was not updated today\n - alias: If between January 1 and March 15\n condition: template\n value_template: '{{ iif((1,1) <= (now().month, now().day) <= (3,15), true,\n false) }}'\n - alias: Pollen is not in the air\n condition: template\n value_template: '{{ is_state_attr(''binary_sensor.pollen_updated_today'',''in_pollen_season'',false)}}'\n - condition: trigger\n id:\n - pre_season_single_time_trigger\n - alias: If in season and pollen is in the air and in trigger timeslot\n condition: and\n conditions:\n - condition: template\n value_template: '{{ states(''sensor.pollen_update_time'') | as_timestamp()\n < states(''sensor.pollen_timestamp_start_of_today'') | float(0) }}'\n alias: If Pollen sensors was not updated today\n - alias: If between January 15 and October 15\n condition: template\n value_template: '{{ iif((1,15) <= (now().month, now().day) <= (10,15), true,\n false) }}'\n - condition: time\n after: '14:59:00'\n before: '20:00:00'\n - condition: template\n value_template: '{{ is_state_attr(''binary_sensor.pollen_updated_today'',''in_pollen_season'',true)}}'\n alias: Pollen is in the air\n - condition: and\n conditions:\n - condition: trigger\n id:\n - button_trigger\n - condition: template\n value_template: '{{ trigger.from_state.state | as_timestamp(0)+5 < now().timestamp()\n }}'\n alias: It is more than 5 seconds ago since last button press\n actions:\n - action: homeassistant.update_entity\n metadata: {}\n data:\n entity_id:\n - sensor.pollen_update_time\n mode: single",
"config": [
{
"name": "pollen update time",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.pollen_update_time",
"device_id": null
}
},
{
"name": "pollen timestamp start of today",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.pollen_timestamp_start_of_today",
"device_id": null
}
},
{
"name": "pollen updated today",
"room": null,
"type": "binary_sensor",
"id": {
"entity_id": "binary_sensor.pollen_updated_today",
"device_id": null
}
},
{
"name": "pollen update feed",
"room": null,
"type": "input_button",
"id": {
"entity_id": "input_button.pollen_update_feed",
"device_id": null
}
}
]
},
{
"id": "'Zone registration: Initialize start values'",
"automation": "- alias: 'Zone registration: Initialize start values'\n description: Will run at HA start. Only need to run once. Can be disabled afterwards\n triggers:\n - trigger: homeassistant\n event: start\n condition:\n - condition: or\n conditions:\n - condition: state\n entity_id: input_text.zone_registration_config\n state: ''\n - condition: state\n entity_id: input_text.zone_registration_config\n state: unknown\n alias: If config is either not set or empty string\n action:\n - if:\n - condition: or\n conditions:\n - condition: state\n entity_id: input_text.zone_registration_config\n state: unknown\n - condition: state\n entity_id: input_text.zone_registration_config\n state: ''\n then:\n - action: input_text.set_value\n data:\n value: '[]'\n target:\n entity_id: input_text.zone_registration_config\n alias: Set config to empty list if unconfigured\n - if:\n - condition: or\n conditions:\n - condition: state\n entity_id: input_text.zone_registration_comment\n state: unknown\n then:\n - action: input_text.set_value\n data:\n value: ''\n target:\n entity_id: input_text.zone_registration_comment\n alias: Set comment to empty if unknown\n - if:\n - condition: or\n conditions:\n - condition: state\n entity_id: input_text.zone_registration_config_label\n state: unknown\n then:\n - action: input_text.set_value\n data:\n value: ''\n target:\n entity_id: input_text.zone_registration_config_label\n alias: Set label to empty if unknown\n - action: shell_command.create_csv_dir\n data: {}\n alias: Create CSV directory if it does not exist\n - action: shell_command.mv_zone_csv_script\n data: {}\n alias: 'Move script from packages to csv directory '",
"config": [
{
"name": "zone registration config",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.zone_registration_config",
"device_id": null
}
},
{
"name": "zone registration comment",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.zone_registration_comment",
"device_id": null
}
},
{
"name": "zone registration config label",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.zone_registration_config_label",
"device_id": null
}
}
]
},
{
"id": "'Zone registration: Fill input select with data'",
"automation": "- alias: 'Zone registration: Fill input select with data'\n description: Populate input selects with zone and person data\n triggers:\n - trigger: homeassistant\n event: start\n id: start\n - trigger: event\n id: reload\n event_type: call_service\n event_data:\n domain: input_select\n action: reload\n condition: []\n action:\n - delay: 00:00:01\n - action: input_select.set_options\n data:\n options: '{{ states.zone | map(attribute=''entity_id'') | list }}'\n target:\n entity_id: input_select.zones\n alias: Add zones to input select\n - action: input_select.set_options\n data:\n options: '{{ states.person | map(attribute=''entity_id'') | list }}'\n target:\n entity_id: input_select.person_entities\n alias: Add persons to input select\n - action: input_select.set_options\n data:\n options: '{{ states(''input_text.zone_registration_config'').replace(''\\'''',''\\\"'')\n | from_json | map(attribute=''name'') | list }}\n\n '\n target:\n entity_id: input_select.zone_registration_config\n alias: Update config names in input select\n mode: single",
"config": [
{
"name": "zone registration config",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.zone_registration_config",
"device_id": null
}
},
{
"name": "zones",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.zones",
"device_id": null
}
},
{
"name": "person entities",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.person_entities",
"device_id": null
}
},
{
"name": "zone registration config",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.zone_registration_config",
"device_id": null
}
}
]
},
{
"id": "'Zone registration: Auto update input select when config changes'",
"automation": "- alias: 'Zone registration: Auto update input select when config changes'\n description: Read config from UI and select zone and person\n triggers:\n - trigger: state\n entity_id: input_select.zone_registration_config\n condition: []\n action:\n - variables:\n selected_config: \"{%- set input_select_sensor = 'input_select.zone_registration_config'\\\n \\ %}\\n{%- set options = state_attr(input_select_sensor,'options') %}\\n{%-\\\n \\ set options_count = options | count() %} \\n{%- for i in range(0,options_count)\\\n \\ %}\\n {%- set selected=options[i] %}\\n {%- if selected==states(input_select_sensor)\\\n \\ %}\\n {{ i }}\\n {%- break %}\\n {%- endif %}\\n{%- endfor %}\\n\"\n selected_person: '{% set options=(states(''input_text.zone_registration_config'',''options'').replace(''\\'''',''\"'')\n | from_json) %}\n\n {{ options[selected_config].person }}\n\n '\n selected_zone: \"{% set options=(states('input_text.zone_registration_config','options').replace('\\\\\\\n '','\\\"') | from_json) %} \\n{{ options[selected_config].zone }}\\n\"\n config_name: \"{% set options=(states('input_text.zone_registration_config','options').replace('\\\\\\\n '','\\\"') | from_json) %} \\n{{ options[selected_config].name }}\\n\"\n - action: input_select.select_option\n data:\n option: '{{ selected_person }}'\n target:\n entity_id: input_select.person_entities\n - action: input_select.select_option\n data:\n option: '{{ selected_zone }}'\n target:\n entity_id: input_select.zones\n - action: input_text.set_value\n data:\n value: '{{ config_name }}'\n target:\n entity_id: input_text.zone_registration_config_label\n - action: homeassistant.update_entity\n data: {}\n target:\n entity_id: sensor.zone_registration_statistics\n mode: single",
"config": [
{
"name": "zone registration config",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.zone_registration_config",
"device_id": null
}
},
{
"name": "zone registration config label",
"room": null,
"type": "input_text",
"id": {
"entity_id": "input_text.zone_registration_config_label",
"device_id": null
}
},
{
"name": "zones",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.zones",
"device_id": null
}
},
{
"name": "person entities",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.person_entities",
"device_id": null
}
},
{
"name": "zone registration config",
"room": null,
"type": "input_select",
"id": {
"entity_id": "input_select.zone_registration_config",
"device_id": null
}
},
{
"name": "zone registration statistics",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.zone_registration_statistics",
"device_id": null
}
}
]
},
{
"id": "'Zone registration: Register configured zone events'",
"automation": "- alias: 'Zone registration: Register configured zone events'\n description: Test configuration and update CSV based on zone enter and leave events\n triggers:\n - trigger: event\n event_type: state_changed\n condition:\n - condition: template\n value_template: '{{ trigger.event.data.entity_id in state_attr(''binary_sensor.zone_registration_config_valid'',''zones'')\n }}\n\n '\n alias: Test if triggering entity id exist as part of zone configuration\n action:\n - variables:\n trigger_person: \"{%- if trigger.event.data.new_state.state | int(0) > trigger.event.data.old_state.state\\\n \\ | int(0) %}\\n {{ trigger.event.data.new_state.attributes.persons | first\\\n \\ if trigger.event.data.new_state.state == 1 else\\n trigger.event.data.new_state.attributes.persons\\\n \\ | reject('in', trigger.event.data.old_state.attributes.persons) | first\\\n \\ }}\\n{% else %}\\n {{ trigger.event.data.old_state.attributes.persons | first\\\n \\ if trigger.event.data.old_state.state == 1 else\\n trigger.event.data.old_state.attributes.persons\\\n \\ | reject('in', trigger.event.data.new_state.attributes.persons) | first\\\n \\ }}\\n{%- endif %}\\n\"\n - condition: template\n value_template: '{{ trigger_person in state_attr(''binary_sensor.zone_registration_config_valid'',''persons'')\n }}\n\n '\n alias: Test if triggering person is part of zone configuration\n - condition: template\n value_template: \"{{ ( is_state('input_boolean.zone_registration_enter','on') \\\n \\ \\n and trigger.event.data.new_state.state | int(0) > trigger.event.data.old_state.state\\\n \\ | int(0) ) \\n or ( is_state('input_boolean.zone_registration_leave','on')\\\n \\ \\n and trigger.event.data.new_state.state | int(0) < trigger.event.data.old_state.state\\\n \\ | int(0) ) }}\\n\"\n alias: Test zone configuration settings for which events to act upon\n - variables:\n zone_config: '{{ state_attr(''binary_sensor.zone_registration_config_valid'',''json'')\n | selectattr(''person'',''eq'',trigger_person) | first}}\n\n '\n filename: '{{ (zone_config.name | regex_replace(find=''[^\\\\w]'',\n\n replace=''_'')).replace(''__'',''_'').lower()+''.csv'' }}\n\n '\n - action: shell_command.zone_registration\n data:\n entry: auto\n filename: '{{ filename }}'\n alias: Update CSV file\n - action: homeassistant.update_entity\n data: {}\n target:\n entity_id: sensor.zone_registration_statistics\n mode: single",
"config": [
{
"name": "zone registration statistics",
"room": null,
"type": "sensor",
"id": {
"entity_id": "sensor.zone_registration_statistics",
"device_id": null
}
},
{
"name": "zone registration config valid",
"room": null,
"type": "binary_sensor",
"id": {
"entity_id": "binary_sensor.zone_registration_config_valid",
"device_id": null
}
},
{
"name": "zone registration enter",
"room": null,
"type": "input_boolean",
"id": {
"entity_id": "input_boolean.zone_registration_enter",
"device_id": null
}
},
{
"name": "zone registration leave",
"room": null,
"type": "input_boolean",
"id": {
"entity_id": "input_boolean.zone_registration_leave",
"device_id": null
}
}
]
}
]