Can someone help me with the configuration of MQTT covers.
My code works, until the set position template. What i try to accomplish is to linearize the movement of the cover with the position slider, via a mathematic equation. Otherwise the first 30% is used to make space between the seperate rows of the cover, and from 30 until 100 it will move up.
Anyway here is my yaml:
cover:
- platform: mqtt
name: 'MQTT Cover'
command_topic: 'domoticz/in'
payload_open: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": 100 }'
payload_close: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": 0 }'
state_topic: 'home/rolluik_tuin/state'
state_open: 100
state_closed: 0
set_position_topic: 'domoticz/in'
set_position_template: '{ "command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": {{ (position*(100-30)/100+30)|int }} }'
optimistic: false
Here my set_position_template works, but as soon as I change it to:
cover:
- platform: mqtt
name: 'MQTT Cover'
command_topic: 'domoticz/in'
payload_open: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": 100 }'
payload_close: '{"command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": 0 }'
state_topic: 'home/rolluik_tuin/state'
state_open: 100
state_closed: 0
set_position_topic: 'domoticz/in'
set_position_template: >-
{%- if position > 0 -%}
'{ "command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": {{ (position*(100-30)/100+30)|int }} }'
{%- else -%}
'{ "command": "switchlight", "idx": 9, "switchcmd": "Set Level", "level": 0 }'
{%- endif -%}
optimistic: false
the template will not work anymore.
Can someone help me to get it working?
p.s. how can I nicely format my forum posts as readable yaml, because my code looks like shit in plain text…
I’m sorry for that