-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easier Home Assistant Zigbee2MQTT light integration - listen to specific topic and not just state #130
Comments
Awesome! This is super helpful for me, as some people asked fo Zigbee2MQTT Integration in the past (#71) but sadly my knowledge wasnt sufficient. Your post is a great intro. One thing though, I suppose |
Hi' @sieren No worries ! 😎 And, as you write, I would also suggest consistant use of JSON messages for Z2M integration as this is the 'standard'. One final suggestion to this Z2M integration. On startup, Homepoint should cycle through all Z2M devices and sync device status by issuing a get command with an empty payload for the device specified key. Get specified key payload (well, in fact all payloads are returned): topic: zigbee2mqtt/[FRIENDLY_NAME]/get
payload: {"state": ""} Set specific attribute: topic: zigbee2mqtt/[FRIENDLY_NAME]/set
payload: {"state": "[ATTRIBUTE]"} Ciao ! 🙋♂️ |
EDIT: Revised HA light automations to handle switches as well as light entities. Hi' @sieren. I've mocked up some Home Assistant automations that via MQTT will provide basic HomePoint integration with Home Assistant entities - Lights, Switches (turn on/off). Also made the one HA automation for Z2M light needed, to provide full integration for these as well. Didn't really known where and if you would want such examples on your Homepoint Github page ? Wish you a lovely weekend! 🍻😎 Homepoint example with Z2M & Home Assistant entities: Please note that Home Assistant entities are entered with {
"wifi": "my_ssid",
"password": "my_password",
"hostname": "HomePoint ILI9341",
"login": "my_login",
"webpass": "my_password",
"mqttbroker": "mqtt://192.168.X.XX",
"mqttusername": "my_username",
"mqttpasswd": "my_password",
"timezone": "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00",
"screenSaverMinutes": 10,
"displayColorInverted": false,
"ledPinPullup": true,
"screenRotationAngle": 1,
"scenes": [{
"name": "Office",
"type": "Light",
"icon": "livingroom",
"devices": [{
"name": "Ceiling",
"setTopic": "homepoint/light.kontor_loft/set",
"getTopic": "homepoint/light.kontor_loft/get",
"onValue": "on",
"offValue": "off"
},
{
"name": "Desk",
"setTopic": "zigbee2mqtt/Office desk lamp/set",
"getTopic": "zigbee2mqtt/Office desk lamp/get",
"onValue": "ON",
"offValue": "OFF"
},
{
"name": "Bed lamp",
"setTopic": "zigbee2mqtt/Office bed lamp/set",
"getTopic": "zigbee2mqtt/Office bed lamp/get",
"onValue": "ON",
"offValue": "OFF"
}]
},
{
"name": "Kitchen",
"type": "Light",
"icon": "kitchen",
"devices": [{
"name": "Kitchen",
"setTopic": "homepoint/light.kokken/set",
"getTopic": "homepoint/light.kokken/get",
"onValue": "on",
"offValue": "off"
}]
},
{
"name": "Terrasse HA",
"type": "Switch",
"icon": "garden",
"devices": [{
"name": "Terrasse",
"setTopic": "homepoint/switch.terrasse_lys/set",
"getTopic": "homepoint/switch.terrasse_lys/get",
"onValue": "on",
"offValue": "off"
}]
},
{
"name": "Terrasse MQTT",
"type": "Switch",
"icon": "garden",
"devices": [{
"name": "Terrasse",
"type": "singleValue",
"setTopic": "terrasse_lys/cmnd/POWER",
"getTopic": "terrasse_lys/cmnd/POWER",
"onValue": "ON",
"offValue": "OFF"
}]
},
{
"name": "Office lux",
"type": "Sensor",
"icon": "power",
"devices": [{
"name": "Kontor lux",
"type": "singleValue",
"firstIcon":"wattage_small",
"jsondata": true,
"firstKey": "illuminance_lux",
"getTopic": "zigbee2mqtt/Office lux"
}]
},
{
"name": "Greenhouse",
"type": "Sensor",
"icon": "door",
"devices": [{
"name": "Greenhouse",
"type": "combinedValues",
"firstIcon": "temperature_small",
"secondIcon": "humidity_small",
"jsondata": true,
"firstKey": "Temperature",
"secondKey": "Humidity",
"getTopic": "tasmota_46FEAB/tele/SENSOR"
}]
},
{
"name": "Outdoor",
"type": "Sensor",
"icon": "door",
"devices": [{
"name": "Outdoor",
"type": "combinedValues",
"firstIcon": "temperature_small",
"secondIcon": "humidity_small",
"jsondata": true,
"firstKey": "temperature",
"secondKey": "humidity",
"getTopic": "zigbee2mqtt/Outdoor"
}]
}]
} First Home Assistant automation is needed to complement HomePoint <--> Z2M integration. Last two automations handles Homepoint integration with Home Assistant entities. In both 'publish HA state' automations you need to enter all your light/switch entities/groups that you use in HomePoint. # We only need to publish HA state changes to HomePoint, as HomePoint publish changes to Z2M bulbs directly
- id: HomePoint - Publish HA Z2M light state change to HomePoint via MQTT
alias: HomePoint - Publish HA Z2M light state change to HomePoint via MQTT
mode: parallel # Use parallel as numerous automations could be running simultanously
trigger:
platform: state
entity_id:
- light.0x680ae2fffe924460_light # Enter you Z2M light entities that are used in HomePoint
- light.0x90fd9ffffe838cb3_light # Homepoint topic for Z2M entities is [friendly_name] NOT [entity_id] !
condition:
condition: template
value_template: "{{ trigger.to_state.attributes.state !=\n trigger.from_state.attributes.state\
\ }}\n"
action:
- service: mqtt.publish
data_template:
topic: zigbee2mqtt/{{trigger.to_state.attributes.friendly_name}}/get # topic: zigbee2mqtt/[entity_id]/get
payload: '{{ trigger.to_state.attributes.state }}' # payload is UPPER case ('ON' or 'OFF')
# Supports all Home Assistant light & switch entities
# Also supports to publish other Home Asssistant entity states to HomePoint (sensors/binary_sensors/zones etc.)
- id: HomePoint - Publish HA light/switch state change to HomePoint via MQTT
alias: HomePoint - Publish HA light/switch state change to HomePoint via MQTT
mode: parallel # Use parallel as numerous automations could be running simultanously
trigger:
entity_id:
- light.kontor_loft # Enter your HA entities/groups that are used in HomePoint
- light.kokken # Homepoint topic for HA entities is [entity_id] NOT [friendly_name] !
- switch.terrasse_lys
- sensor.media_source
platform: state
condition:
condition: template
value_template: "{{ trigger.to_state.state !=\n trigger.from_state.state }}\n"
action:
- service: mqtt.publish
data_template:
topic: homepoint/{{trigger.to_state.entity_id}}/get # topic: homepoint/[entity_id]/get
payload: '{{states(trigger.entity_id)}}' # payload is lower case ('on' or 'off')
# Supports all Home Assistant light & switch entities
- id: Homepoint - Push state change from HomePoint device to light/switch via HA service call
alias: Homepoint - Push state change from HomePoint device to light/switch via HA service call
mode: parallel # Use parallel as numerous automations could be running simultanously
trigger:
platform: mqtt
topic: homepoint/+/set # Note: Will trigger on ALL entities used in topic: homepoint/*/set !!
action: # Turn light on/off depending on payload received
service_template: "{% if trigger.payload == 'on' %}\n homeassistant.turn_on\n{% else\
\ %}\n homeassistant.turn_off\n{% endif %}\n"
data_template:
entity_id: '{{ trigger.topic.split(''/'')[1] }}' # Get entity_id from topic
|
Can I understand this in such a way that, for example, an alarm panel can be designed that passes the commands to HA, e.g. via M5Stack Core2 or better M5Paper? |
Hi' @fastender. Well, Matts HomePoint user interface has clearly been developed for a specific use purpose - To handle simple entities as lights/switches/sensors and display their status. And does actually all that in quite a convincing, no nonsense way 🙂 HomePoint could (hopefully) develop into a more complex userinterface. It certainly has the potential. Homepoint could, as is, act as a simple alarm panel. But not with a full keypad for entering numbers and fancy graphics etc. Ciao ! |
@htvekov I'm confused by your latest comment. The reason im asking is, this is so much custom stuff, I'm thinking of just adding a Update: Looking at the documentation again, doesnt using the "friendly_name" cover most of the cases and reduce complexity? While I want to support Zigbee2MQTT and HA, I have to keep some parts of HomePoint fairly generic to make it work with other tools, which would mean additional configuration on the user side. |
Hi' @sieren Well, I'll admit it's a little confusing. First of all: Adding a specific integration property for each device, will most likely solve many (unforeseen) future issues. Z2M uses Z2M device Z2M devices.yaml example: # Lights
'0x680ae2fffe924460':
friendly_name: Office desk lamp Depending on settings and at what point Home Assistant autodiscovers the exposed Z2M devices, HA's Same Z2M device as entity in HA: But as both HA's Hope all above makes any sense at all, Matt ? So to wrap this up I would suggest to keep this as simple as possible.
Suggestions, Matt ? 😉 Ciao ! |
Picked up works on this. Here's my config idea. I suppose while I am doing so I can add a second service called "HAMQTT" that is specific to how HomeAssistant Publishes it's own automations through the Would that make sense? Zigbee2MQTT
HomeAssistant
|
Hi' Matt. I think it's a sensible idea to separate the different 'integrations' into different modes. It's not really a Z2M/HA integration more likely a 'representation' of the device/entity on the HomePoint screen. If you at some point have the urge to develop 'real' HA integration, the easiest method imo is through HA MQTT autodiscovery. The full blown HA integration would be somewhat more of a challenge. With this sort of implementation, the individual buttons would become entities in HA. And you cold tie state changes for these buttons up in automations to do whatever. But some of the simplicity would be gone doing just that. Ciao ! |
This sounds like what HASwitchPlate accomplished with their code. https://github.com/aderusha/HASwitchPlate. Is this the type of thing that you are talking about? |
Yeah, @cbrightly is right. Maybe that's the better fit? |
Hi' @sieren I totally agree. Keep HomePoint as the simple solution for basic tasks. @fvanroie has practically rewritten aderusha's entire original hasp code and made a fully object oriented touchscreen display UI - hasp-lvgl So no need to go in the same direction and do exactly the same as aderusha and fvanroie has done. Ciao ! |
Ahh, thanks for the pointer! |
Hi' Matt. That library is simply awesome... This library will most likely push most future display projects towards touch screens. I'll definitely vote for that library if you're to rewrite HomePoint for a graphics library update 👍 Ciao ! |
👍🎉⚡🚀😎🙋♂️ |
EDIT: Updated HA example with needed
mode
when groups of lights are turned on/off simultanously.EDIT: Revised
setTopic
for JSON exampleHi' @sieren
First of all: Great piece of software ! 👍🎉😎
I've had Homepoint in the test pipeline for quite a few months and finally I got time to test with my set up.
My initial struggle was not with Homepoint, but rather my newly bought, but semi defective, M5 stack.
Dead CP210X chip 😖, which took me half a day to realise before I finally programmed the ESP32 directly without further hazzle.
My initial impression of Homepoint - I love it ! 🤗🤗
I searched a lot, but found next to nothing regarding Z2M/MQTT Home Assistant integration - use examples/experiences etc.
So I had to move forward by trial and error 😉
It would really be helpful if users, with similar setup like me, could define a specific JSON payload key for Homepoint to read the light status (
getTopic
)Example - (for
type: Light
as well):Define that
jsondata
should be used forgetTopic
and the key to be used infirstKey
Then Homepoint could read state directly from HA Z2M integrated lights via standard MQTT messages like this below:
Zigbee2MQTT:info 2021-01-04 23:57:45: MQTT publish: topic 'zigbee2mqtt/Office bed lamp', payload '{"brightness":251,"color":{"x":0.491,"y":0.39},"linkquality":105,"state":"ON","update":{"state":"idle"},"update_available":false}'
That would be awesome and much easier without the need for extra automation ! 😎
For now, I use following Home Assistant automation to push all states changes (for a list of MQTT light entities) to Homepoint on topic
zigbee2mqtt/LIGHTS_FRIENDLY_NAME/get
with payloadstate
Happy New Year ! 🎉🚀
Ciao !
The text was updated successfully, but these errors were encountered: