Domoticz connect to Home Assistant

Hi Guys,
is there really no one here who can help me?
I want to control the blinds via Homme Assistant.
Thanks in advance…
MQTT Domoticz

These are the data from the MQTT Domoticz.

“AddjMulti” : 1.0,
“AddjMulti2” : 1.0,
“AddjValue” : 0.0,
“AddjValue2” : 0.0,
“BatteryLevel” : 255,
“CustomImage” : 0,
“Data” : “Set Level: 74 %”,
“Description” : “”,
“Favorite” : 1,
“HardwareID” : 7,
“HardwareName” : “Home”,
“HardwareType” : “OpenZWave USB”,
“HardwareTypeVal” : 21,
“HaveDimmer” : true,
“HaveGroupCmd” : true,
“HaveTimeout” : false,
“ID” : “00001301”,
“Image” : “Light”,
“IsSubDevice” : false,
“LastUpdate” : “2017-09-23 08:03:20”,
“Level” : 74,
“LevelInt” : 74,
“MaxDimLevel” : 100,
“Name” : “Tapparella Soggiorno”,
“Notifications” : “false”,
“PlanID” : “2”,
“PlanIDs” : [ 2 ],
“Protected” : false,
“ShowNotifications” : true,
“SignalLevel” : “-”,
“Status” : “Set Level: 74 %”,
“StrParam1” : “”,
“StrParam2” : “”,
“SubType” : “Switch”,
“SwitchType” : “Blinds Percentage Inverted”,
“SwitchTypeVal” : 16,
“Timers” : “false”,
“Type” : “Light/Switch”,
“TypeImg” : “blinds”,
“Unit” : 1,
“Used” : 1,
“UsedByCamera” : false,
“XOffset” : “0”,
“YOffset” : “0”,
“idx” : “73”
}

WHY
Look like Just a Json statement
Whats the topic

 - platform: mqtt
    name: "Its Name you want to call it"
    state_topic: "????"
    value_template: "{{value_json.SwitchType }}"

should return “Blinds Percentage Inverted”

Domoticz topic is
state_topic: “domoticz/out”

i need on, off stop and the state of the shutters.

how Dom do it

Hi

I opened the shutters from 24% to 51%, this is the output from domoticz.
what do I have to enter in Homme Assistant?

domoticz/out {
“Battery” : 255,
“RSSI” : 12,
“description” : “”,
“dtype” : “Light/Switch”,
“id” : “00000C01”,
“idx” : 62,
“name” : “Wohnzimmer Garagenseite”,
“nvalue” : 2,
“stype” : “Switch”,
“svalue1” : “24”,
“switchType” : “Blinds Percentage Inverted”,
“unit” : 1
}

domoticz/out {
“Battery” : 255,
“RSSI” : 12,
“description” : “”,
“dtype” : “Light/Switch”,
“id” : “00000C01”,
“idx” : 62,
“name” : “Wohnzimmer Garagenseite”,
“nvalue” : 2,
“stype” : “Switch”,
“svalue1” : “51”,
“switchType” : “Blinds Percentage Inverted”,
“unit” : 1

that’s my configuration so far

  • platform: mqtt
    name: “Wohnzimmer Garagenseite”
    state_topic: “domoticz/out”
    command_topic: ‘{{value_json.nvalue}}’ ???
    value_template: ‘{{value_json.SwitchType}}’???

ON?
OFF?
STOP?
STATUS?

Thanks in advance…

Nobody can help me, do you have any idea how I can solve this?

Why not just forget your domoticz and change to Hass?

i did the same a few weeks ago, and Hass is so much better for everything.

1 Like

you are trying to create something with mqtt.
so go to https://www.home-assistant.io/components/
and search for mqtt

then you get a lot of device types.
click on the one you want to create and read that doc how to do it.

in your case probably a cover.

In domoticz you have to configure mqtt, is used mosquitto.

If you send a json to domoticz/in the blind will move, in my case it is idx 9, and I made the following automation for that:

- alias: rolluik-tuin set position
  initial_state: 'on'
  trigger:
     - platform: mqtt
       topic: 'home/rolluik_tuin/setpos'
  condition:
    condition: template
    value_template: '{{ trigger.payload|int < 101 }}'
  action:
    - service: mqtt.publish
  data_template:
    topic: 'domoticz/in'
    payload_template: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": {{trigger.payload}}}' 

I also defined a MQTT cover in HA:

# Covers
cover:
  - platform: mqtt
    name: 'MQTT Cover'
    command_topic: 'home/rolluik_tuin/setpos'
    payload_open: '100'
    payload_close: '0'
    payload_stop: '101'
    position_topic: 'home/rolluik_tuin/confirm'
    set_position_topic: 'home/rolluik_tuin/setpos'
    set_position_template: '{{ ((position)*0.7+30)|int if position > 0 else 0 }}'
    optimistic: false

I use intermediate mqtt topics to send my open/close/stop payloads to, and I use a template for setting the position. My previous function looks to the setpos topic, and sends it domoticz.

I do a little math with my position, to make the position the real position, when your cover is almost closed it will move a lot to shift all separate rows against each other, that is in my case 30% of the total motion.

I also have function which reports back the state to the MQTT cover, when it is changed from domoticz:

 rolluik-tuin get position
  initial_state: 'on'
  trigger:
     - platform: mqtt
       topic: 'domoticz/out'
  condition:
    condition: template
    value_template: '{{ trigger.payload_json.idx == 9 }}'
  action:
    - service: mqtt.publish
      data_template:
        topic: '{{ "home/rolluik_tuin/current" if as_timestamp(now())-as_timestamp(states.automation.rolluiktuin_get_position.last_updated) < 1 else ( "home/rolluik_tuin/confirm" if trigger.payload_json.svalue1|int == states.sensor.rlk_SETPOINT.state|int else "home/rolluik_tuin/setpoint" ) }}'
        payload_template: '{{ [((trigger.payload_json.svalue1|float-30)/0.7),0]|max|int if trigger.payload_json.svalue1|int == states.sensor.rlk_SETPOINT.state|int else trigger.payload_json.svalue1|int }}' 

What will happen when the cover is moved from domoticz, domoticz out will first send the new setpoint, then it will report the actual position, and when the cover reaches the setpoint it will send that sendpoint again. I split these values and store them in three sensors, SETPOINT, CONFIRM and CURRENT:

  - platform: mqtt
    name: rlk_CURRENT
    state_topic: 'home/rolluik_tuin/current'
  - platform: mqtt
    name: rlk_SETPOINT
    state_topic: 'home/rolluik_tuin/setpoint'
  - platform: mqtt
    name: rlk_CONFIRM
    state_topic: 'home/rolluik_tuin/confirm'

To make the stop button of the MQTT cover work, I use that current value. If my cover moves and I want to stop it somewhere, i will resend the setpoint, receive the actuel value, and send the actual value as new setpoint, and it stops where it is. This is the code to stop:

- alias: rolluik-tuin stop
  initial_state: 'on'
  trigger:
     - platform: mqtt
       topic: 'home/rolluik_tuin/setpos'
  condition:
    condition: template
    value_template: '{{ trigger.payload|int == 101 }}'
  action:
    - service: mqtt.publish
      data_template:
        topic: 'domoticz/in'
        payload_template: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level":  {{states.sensor.rlk_SETPOINT.state|int}}}' 
    - delay:
        milliseconds: 500
    - service: mqtt.publish
      data_template:
        topic: 'domoticz/in'
        payload_template: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": {{states.sensor.rlk_CURRENT.state|int}}}' 

To summarize:

  • I set up MQTT in domoticz and HA, and figured out the idx of that cover,
  • I configure an MQTT cover in HA
  • Made an automation to set the position by sending it to domoticz/in
  • Made an automation to stop the cover
  • Made an automation to handle changes from domoticz, and get the actual value of the cover, used in the stop function
  • To store the SETPOINT, CURRENT and CONFIRM value I created three mqtt sensors

That value of 30 in that equations is the value of the cover slider in domoticz, when your cover just reaches the bottom of your windows frame. To fully close it needs in my case still 30%, in your case it can be 25. Then all instances of 30 become 25, and all instances of 0.7 become 0.75, and is it 20% it will become 20 and 0.8.

If you fill in your idx nummer, and just put my code in your yaml files, it should work.

Good luck

1 Like

Hi Folks,

I figured rather than starting a new thread I might start here.

So what am I trying to achieve? Something very basic in my eyes but I cannot solve the problem for some reason. I have a Domoticz server that pulls statistical data from my Solar Inverter… which works fine. Within that data is a real time feed of the Kilowatt Hours the solar inverter is generating, but after trying most of the suggestions in here I am still failing.

I connected the domoticz server to MQTT, and so the feed from the domoticz/out MQTT looks like this…

{
	"Battery" : 255,
	"RSSI" : 12,
	"description" : "",
	"dtype" : "General",
	"hwid" : "2",
	"id" : "00000101",
	"idx" : 8,
	"name" : "kWh Meter",
	"nvalue" : 0,
	"stype" : "kWh",
	"svalue1" : "1480.000",
	"svalue2" : "27046000.000",
	"unit" : 1
}

The only data I want to grab from above is the…
“stype” : “kWh”,
“svalue1” : “1480.000
which I want to feed into the HA energy monitor as the constant kWh i.e. the 1480.000 figure that constantly updates.

I have tried a number of approaches, including NodeRed to grab the data I need and then make it available to HA, but that has failed so far.

Would appreciate any advice, I hope there is a really easy way to feed the domoticz kWh figure into the HA energy setup.

You just create an MQTT sensor, and set Domoticz to not output everything to /out but instead to output to output to Index.
Then you should see the sensor you want on domoticz/out/8

So your sensor would be:

sensor:
  - platform: mqtt
    topic: domoticz/out/8
    value_template: "{{ value_json.svalue1|float(0) }}"
    device_class: energy
    name: Solar kWh Meter
    state_class: total # you will need to check this
    unique_id: 2d179ccb-bd7a-4fa6-928a-195472b1b313
    unit_of_measurement: kWh

You can generate UUIDs here: https://www.uuidgenerator.net/
And you need to check here: Sensor Entity | Home Assistant Developer Docs to see which state class you should be using… (I suspect you might want total_increasing)

Hope that helps.

Hello Andrew and happy new year,

I tried what you suggested, but the config wouldn’t save until I changed to the config below:-

# kWh Solar from Domoticz
 - platform: mqtt
   state_topic: "domoticz/out/8"
   value_template: "{{ value_json.svalue1|float(0) }}"
   device_class: energy
   name: Solar kWh Meter
   state_class: total_increasing # you will need to check this
   unique_id: c17e1348-d4ee-47ed-b790-4963727d94c0
   unit_of_measurement: kWh

I tried to check if something was happening under Developer Tools, but this is what I found…

Also, when I added the item to the energy dashboard I found this…

Which kind of makes me think either the mqtt data is not coming through, or there is something I have configured incorrectly?

The first step is to use MQTT Explorer to ensure that Domoticz is indeed outputting to domoticz/out/$IDX otherwise domoticz/out/8 will not exist.
From my time back in using for Domoticz for many years before making the move to Home Assistant, I believe Domoticz needed to be restarted after messing with certain settings, and I feel like MQTT was one of them. (Or at least disable and then re-renable it)

EDIT:

{% set j = {
	"Battery" : 255,
	"RSSI" : 12,
	"description" : "",
	"dtype" : "General",
	"hwid" : "2",
	"id" : "00000101",
	"idx" : 8,
	"name" : "kWh Meter",
	"nvalue" : 0,
	"stype" : "kWh",
	"svalue1" : "1480.000",
	"svalue2" : "27046000.000",
	"unit" : 1
}
%}
{{ j.svalue1|float(0) }}

Pasting that in Developer Tools > Template Editor, returns a number type, and the value is 1480 so it’s definitely correct. And just in case {{ j['svalue1']|float(0) }} also returns 1480.

Hi Andrew,

Here’s some data for you… Here’s the copy from MQTT Explorer…

{
	"Battery" : 255,
	"RSSI" : 12,
	"description" : "",
	"dtype" : "General",
	"hwid" : "2",
	"id" : "00000101",
	"idx" : 8,
	"name" : "kWh Meter",
	"nvalue" : 0,
	"stype" : "kWh",
	"svalue1" : "140.000",
	"svalue2" : "27058000.000",
	"unit" : 1
}

And here’s the line in MQTT Explorer… Edit: I am pretty sure the MQTT topic is: domoticz/out and not domoticz/out/8 but I could be wrong?

And more detail from MQTT Explorer…

I will restart HA at the server level and see if that helps.

Thanks again for the advice, it is very much appreciated.

It IS domoticz/out which is why I said in my first post -

Which should change the output to domoticz/out/IDX so there will be a topic for every IDX

https://www.domoticz.com/wiki/MQTT#Domoticz_to_MQTT

  • if the publish topic of the MQTT hardware is set to Index then the publish topic will be domoticz/out/$idx were $idx is the idx number of the device

If you can’t change the output format of Domoticz MQTT because you already have other things relying on it, then you would need to change your state topic back to domoticz/out and do something like this in your value_template:

value_template: "{{ states('sensor.solar_kwh_meter')|float(0) if value_json.idx != 8 else value_json.svalue1|float(0) }}"

If I’m right (it’s nearly 8am and I haven’t been to sleep yet) - then it will update the sensor with the existing sensor state if the message received is not for idx 8, otherwise it will update the sensor state to the value in the JSON message

Hi Andrew… humble apology, I have now set Domoticz mqtt to index. It won’t trigger until the morning when the solar is generating, so I will see what happens.

Thanks again for the awesome help, really do appreciate it. Hope you managed to get some sleep👍

1 Like

An hour apparently - between half 3 and half 4. Then however much sleep I got between 11:30 and 3ish. Not the best start to the new year :wink:

Hi Andrew,

That works perfectly. It’s a bit of a round about way to get the data, but what the heck it works.

Thank you so much for the help. Now I just need to get the data out of my smart meter, but that’s another step on the journey. Hope you have a great weekend.

Thanks, Mark

1 Like

Yup, the chances are that there are better options, either a custom integration for Home Assistant that already exists, or maybe it has a web interface that we can scrape? What is the make and model of the inverter ?

It’s an old SolarMax Inverter… only talks text based via an ethernet interface. Not many options around for these older inverters.

Interestingly, the Energy dashboard is behaving weird, so I may need to tweak the settings, but at least it appears the data may be getting through.