First, thank you for sharing this. I was just beating my head against the wall trying to get off of using only binding (I know the value for redundancy but for a variety of reasons I prefer to use HA)
Second, just for anyone else who can be an idiot like me, when it comes to adding the sensor it goes under “mqtt:” not under template or sensors or whatever else. I don’t have any other custom MQTT devices so it threw me off for a bit trying to find where it went. Also from what I know, unique_id can be whatever as long as it’s unique.
Here’s an example of a complete setup in your HA config file:
mqtt:
- sensor:
- name: "Dining Room Switch K MQTT"
unique_id: "1958669490006"
state_topic: "zigbee2mqtt/Dining Room Switch K"
value_template: "{{ value_json.action }}"
json_attributes_topic: "zigbee2mqtt/Dining Room Switch K"
json_attributes_template: "{{ value_json | tojson }}"
Hi,
I’m a bit of a newb to this, but I’m getting the following error in relation to this automation:
Logger: homeassistant.components.automation.zigbee2mqtt_lutron_aurora_dimmer_control
Source: components/automation/__init__.py:669
integration: Automation (documentation, issues)
First occurred: 3:43:07 AM (1 occurrences)
Last logged: 3:43:07 AM
Error rendering variables: UndefinedError: 'dict object' has no attribute 'to_state'
And the following warning as well:
Logger: homeassistant.helpers.template
Source: helpers/template.py:2613
First occurred: 3:42:50 AM (37 occurrences)
Last logged: 3:45:48 AM
Template variable warning: 'homeassistant.helpers.template.Wrapper object' has no attribute 'action' when rendering '{{ attrs["action"] }}'
Template variable warning: 'homeassistant.helpers.template.Wrapper object' has no attribute 'action_level' when rendering '{{ attrs["action_level"] }}'
Template variable warning: 'homeassistant.helpers.template.Wrapper object' has no attribute 'action_transition_time' when rendering '{{ attrs["action_transition_time"] }}'
Template variable error: 'dict object' has no attribute 'to_state' when rendering '{{ trigger.to_state.attributes }}'
Any idea how to fix? I added the entry to my config similar as to how Robert did it in the message above mine.
This works…
1.) Import blueprint from drinfernoo
2.) Make a new sensor referencing wmaker’s post. You can either make a separate yaml or include it directly in your configuration.yaml. Use the file editor add-on to make your life easier.
# Custom Additions:
# You can uncomment the line below and optionally place the sensor below
# inside of sensor.yaml - it's up to you!
#sensor: !include sensor.yaml
mqtt:
sensor:
- name: "Switch_Lutron-Aurora-1"
unique_id: "0xffff000fe7fb806b"
state_topic: "zigbee2mqtt/Switch_Lutron-Aurora-1"
value_template: "{{ value_json.action }}"
json_attributes_topic: "zigbee2mqtt/Switch_Lutron-Aurora-1"
json_attributes_template: "{{ value_json | tojson }}"
3.) When you create the automation from the blueprint use the new sensor you just created (name above) and NOT the action or brightness entities.
4.) Voila! Click for on/off. Turn to dim. Only minor caveat, the dimming isn’t very graceful. But it works!