Domoticz connect to Home Assistant


#1

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”
}


#2

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”


#3

Domoticz topic is
state_topic: “domoticz/out”

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


#4

how Dom do it


#5

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…


#6

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


#7

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.


#8

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.


#9

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