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