Zigbee2Mqtt : La configuration package ultime
Zigbee2mqtt c’est la vie. Tout ikea, philips xiaomi sans aucun hub. Sans aucun cloud…
Et en plus, zigbee2mqtt+HomeAssistant = AESD (amour éternel sans divorce…) Configurer tout ca dans Home Assistant ? Deux copier/coller !
Zigbee2Mqtt : Le package ?
Les packages dans HA c’est la possibilité de créer sensors, scripts, automation et tout le reste autour d’un sujet particulier dans un fichier unique. l’avantage : Pas besoin de retoucher tous les fichiers et une logique fonctionnelle très forte.
Voici donc mon package pour zigbee2mqtt :
Il suffit de copier/coller le contenu dans un fichier zigbee2mqtt.yaml et le placer dans config/packages/
Ca ajoutera :
- La conf du niveau de log
- La possibilité de renommer les topics facilement (autre tuto à venir)
- L’activation pour le permit-join ou la suppression d’un pairing en un clic
- …
# Input select for Zigbee2mqtt debug level
input_select:
zigbee2mqtt_log_level:
name: Niveau de log
options:
- debug
- info
- warn
- error
initial: info
icon: mdi:format-list-bulleted
# Input text to input Zigbee2mqtt friendly_name for scripts
input_text:
zigbee2mqtt_old_name:
name: Ancien nom
zigbee2mqtt_new_name:
name: Nouveau nom
zigbee2mqtt_remove:
name: Device à retirer
# Scripts for renaming & removing devices
script:
zigbee2mqtt_rename:
alias: Renommer le device
sequence:
service: mqtt.publish
data_template:
topic: zigbee2mqtt/bridge/config/rename
payload_template: >-
{
"old": "{{ states.input_text.zigbee2mqtt_old_name.state | string }}",
"new": "{{ states.input_text.zigbee2mqtt_new_name.state | string }}"
}
zigbee2mqtt_remove:
alias: Retirer le device
sequence:
service: mqtt.publish
data_template:
topic: zigbee2mqtt/bridge/config/remove
payload_template: "{{ states.input_text.zigbee2mqtt_remove.state | string }}"
# Timer for joining time remaining (120 sec = 2 min)
timer:
zigbee_permit_join:
name: Temps restant
duration: 120
sensor:
# Sensor for monitoring the bridge state
- platform: mqtt
name: Bridge state
state_topic: "zigbee2mqtt/bridge/state"
icon: mdi:router-wireless
# Sensor for Showing the Zigbee2mqtt Version
- platform: mqtt
name: Zigbee2mqtt Version
state_topic: "zigbee2mqtt/bridge/config"
value_template: "{{ value_json.version }}"
icon: mdi:zigbee
# Sensor for Showing the Coordinator Version
- platform: mqtt
name: Coordinator Version
state_topic: "zigbee2mqtt/bridge/config"
value_template: "{{ value_json.coordinator }}"
icon: mdi:chip
- platform: mqtt
name: Zigbee2mqtt Networkmap
# if you change base_topic of Zigbee2mqtt, change state_topic accordingly
state_topic: zigbee2mqtt/bridge/networkmap/raw
value_template: >-
{{ now().strftime('%Y-%m-%d %H:%M:%S') }}
# again, if you change base_topic of Zigbee2mqtt, change json_attributes_topic accordingly
json_attributes_topic: zigbee2mqtt/bridge/networkmap/raw
# Switch for enabling joining
switch:
- platform: mqtt
name: "Zigbee2mqtt Main join"
state_topic: "zigbee2mqtt/bridge/config/permit_join"
command_topic: "zigbee2mqtt/bridge/config/permit_join"
payload_on: "true"
payload_off: "false"
automation:
# Automation for sending MQTT message on input select change
- alias: Zigbee2mqtt Log Level
initial_state: "on"
trigger:
platform: state
entity_id: input_select.zigbee2mqtt_log_level
action:
- service: mqtt.publish
data:
payload_template: "{{ states('input_select.zigbee2mqtt_log_level') }}"
topic: zigbee2mqtt/bridge/config/log_level
# Automation to start timer when enable join is turned on
- id: zigbee_join_enabled
alias: Zigbee Join Enabled
hide_entity: true
trigger:
platform: state
entity_id: switch.zigbee2mqtt_main_join
to: "on"
action:
service: timer.start
entity_id: timer.zigbee_permit_join
# Automation to stop timer when switch turned off and turn off switch when timer finished
- id: zigbee_join_disabled
alias: Zigbee Join Disabled
hide_entity: true
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.zigbee_permit_join
- platform: state
entity_id: switch.zigbee2mqtt_main_join
to: "off"
action:
- service: timer.cancel
data:
entity_id: timer.zigbee_permit_join
- service: switch.turn_off
entity_id: switch.zigbee2mqtt_main_join
Plus qu’à référencer le package dans votre configuration.yaml
homeassistant:
...
packages:
zigbee2mqtt: !include packages/zigbee2mqtt.yaml
Voilà, vous avez tout le nécessaire pour vous créer une vue lovelace complète.
Voici en exemple la mienne :
Note : j’ai ajouté la custom card sympa custom:zigbee2mqtt-networkmap
- badges:
- sensor.bridge_state
- sensor.zigbee2mqtt_version
- sensor.coordinator_version
- switch.zigbee2mqtt_main_join
cards:
- cards:
- entities:
- input_select.zigbee2mqtt_log_level
- switch.zigbee2mqtt_main_join
- timer.zigbee_permit_join
show_header_toggle: false
title: Paramètres généraux
type: entities
type: vertical-stack
- cards:
- entity: sensor.zigbee2mqtt_networkmap
type: 'custom:zigbee2mqtt-networkmap'
type: vertical-stack
- cards:
- aspect_ratio: 8/1
icon: 'mdi:eye-plus'
name: Mqtt devices
tap_action:
action: navigate
navigation_path: >-
/config/integrations/config_entry/d92e4ee0f4f24d3db6d0ca8282c1c484
type: 'custom:button-card'
- aspect_ratio: 8/1
icon: 'mdi:eye-plus'
name: Zigbee2Mqtt add-on et logs
tap_action:
action: navigate
navigation_path: /hassio/addon/7ad98f9c_zigbee2mqtt
type: 'custom:button-card'
- entities:
- input_text.zigbee2mqtt_old_name
- input_text.zigbee2mqtt_new_name
- script.zigbee2mqtt_rename
- type: divider
- input_text.zigbee2mqtt_remove
- script.zigbee2mqtt_remove
show_header_toggle: false
title: Boite à outils
type: entities
type: vertical-stack
icon: 'mdi:zigbee'
path: mqtt
title: Mqtt
Prochain article : le workflow d’ajout !