Communicating with home assistant

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

Post Reply
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Communicating with home assistant

Post by akamming »

Hi,

Just 2 Share the knowledge:

I like home assistant because of the big community, the nice dashboarding and the many many integrations, but i also like domoticz e.g. because of the P1 integration (and the nice reports on it), and the easy way of scripting (HA has no alternative for something like dzVents).

Since I cannot choose between the 2 i decided to use the benefits of both. This is how i do it:
1. Since both support the MQTT AD protocol: For every integration which support is: Add the devices by MQTT AD. This will make the devices available in both instances
2. For those who don't: Using the MQTT Client Interface integration in domoticz to connect the 2. Note: For this to work every device needs to have it's own state topic. So in the settings for MQTT CLient interface, set Publish Topic either to "Index" or "Name"

By setting the interface under 2 you now have the perfect mechanism to have the 2 instances to talk to each other:

For sending devices updates from HA to Domoticz:
- Create a virtual device in domoticz (mirroring the device in home assistant)
- Create an automation in home assistant with the folling properties
  • Trigger: The sensor change
  • Condition: None
  • Action: mqtt.publish with the topic "domoticz/in" and as payload something like { "command": "udevice", "idx": <the idx of your virtual sensor in domoticz>, "nvalue": 0, "svalue": "{{ states.<the sensor name of your sensor in home assistant>.state }}"}


For sending device updates from Domoticz to HA:
- Add the line "mqtt: !include mqtt.yaml" to you homeasistant configuration.yaml
- Create the devices you'd like by describing them in the mqtt.yaml file. :

Code: Select all

sensor:
# Gas usage
  - state_topic: "domoticz/out/<index of your domoticz sensor>"
    name: "<name of the device>"
    value_template: '{{ value_json.svalue1  }}'
    unit_of_measurement: '<unit of measurement>'
    device_class: <device class>
    state_class: <state class>
  - <repeat the above lines for every sensor you would like to read from domoticz>
e.g. hereby the example of which i currently use to import my utility devices to home assistant:

Code: Select all

#P1 meter
sensor:
  - state_topic: "domoticz/out/6"
    name: "T1"
    value_template: '{{ value_json.svalue1 | float / 1000  }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/6"
    name: "T2"
    value_template: '{{ value_json.svalue2 | float / 1000 }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/6"
    name: "T Total"
    value_template: '{{ (value_json.svalue2 | float + value_json.svalue1 | float ) / 1000 }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/6"
    name: "R1"
    value_template: '{{ value_json.svalue3 | float / 1000 }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/6"
    name: "R2"
    value_template: '{{ value_json.svalue4 | float / 1000 }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/6"
    name: "R total"
    value_template: '{{ (value_json.svalue4 | float + value_json.svalue3 | float) / 1000 }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/6"
    name: "Usage"
    value_template: '{{ value_json.svalue5 }}'
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
  - state_topic: "domoticz/out/6"
    name: "Delivery"
    value_template: '{{ value_json.svalue6 }}'
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement

# Gas usage
  - state_topic: "domoticz/out/10"
    name: "Gas Verbruik"
    value_template: '{{ value_json.svalue1  | float / 1000 }}'
    unit_of_measurement: 'm³'
    device_class: gas
    state_class: total_increasing

# Water usage
  - state_topic: "domoticz/out/598"
    name: "Water Verbruik"
    value_template: '{{ value_json.svalue1  }}'
    unit_of_measurement: 'L'
    device_class: water
    state_class: total_increasing

#Solar Panels
  - state_topic: "domoticz/out/31"
    name: "Solaredge Delivery Total"
    value_template: '{{ value_json.svalue2 | float / 1000 }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
  - state_topic: "domoticz/out/31"
    name: "Solaredge Actual Delivery"
    value_template: '{{ value_json.svalue1 }}'
    unit_of_measurement: "W"
    device_class: power
    state_class: measurement
Have fun! I am very happy now that i can use the strengths of both Home Assistant and Domoticz using this config!
solarboy
Posts: 300
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Communicating with home assistant

Post by solarboy »

Nice work, I'll give this a try.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Communicating with home assistant

Post by akamming »

Just found out how publish a domoticz switch as a MQTT switch in home assistant: Add the following to your mqtt.yaml file (see instructions above in this topic how to create that file in HASS):

Code: Select all

switch:
  - state_topic: "domoticz/out/<idx>"
    value_template: "{% if value_json.nvalue==1 -%}ON{%- else -%}OFF{%- endif %}"
    command_topic: "domoticz/in"
    unique_id: "<uniqueid>"
    name: "<name>"
    command_template: "{ \"command\": \"switchlight\", \"idx\": <idx>, \"switchcmd\": \"{{ \"On\" if value==\"ON\" else \"Off\" }}\" }"
make sure to replace
  • <idx> with the idx of the switch in domoticz
  • <unique_id> with some unique identifier (create whatever you want, as long as it's unique ;-))
  • <name> with the name you would like the switch to have in HASS
also make sure the "Prevent Loop" setting in your mqtt client gateway hardware setting is set to false, otherwise synchronisation might fail between HASS and domoticz
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest