In DevTools’ section, under State panel, my two sensor are reacting correctly showing on or off, but the problem is that the cover’s state is always unknown.
I believe that something is wrong in my value_template attribute, but I googled all night long without finding a solution.
Does your state_topic change? Value_template is ment to take the response from the state topic and parse the answer. I’m not 100% sure that you can access the state machine like you are trying to do at that point.
Hi @petro, thanks for your quick response.
I tested the code of value_template in the DevTools’ section, under Template panel and it works.
I just want to say to the cover - that right now does not know anything about its state: “Hey Cover, if S1 is on you are open, if S2 is on you are closed, else you are moving.”
Yes I understand that but your value template is accessing the state machine. It will work when the state machine is present. If the state machine not present, it’ll never work.
So your state topic never changes? Try removing just the state_topic and see what happens.
Thanks @petro, I tried removing state_topic: "stat/sf-gate/POWER" line from my configuration, and now the gate results always open.
I’ll try to explain how my gate’s relay works.
I have a Sonoff Basic that trigger ON the relay and then automatically OFF after 0.4s when I want it to open the gate. It’s just like a ‘human press of button’. Sonoff don’t know anything about the state of the gate as it doesn’t depend on the state of the relay (it’s always off, it goes on for 0.4s for opening then the closure is automatic after a certain time); that’s why I set this sensors up.
Another solution could be to set-up Tasmota’s Rules (on the relay) to publish on an MQTT topic directly the state of the gate (given from sensors) and so config the cover entity’s position_topic on that topic.
If you want to indicate an intermediate position, something between open and closed, MQTT cover offers the position_topic:
position_topic
(string)(Optional)
The MQTT topic subscribed to receive cover position messages. If position_topic is set state_topic is ignored.
However, I don’t believe value_template works with position_topic therefore it presents a problem for you to interpret the states of the two magnetic sensors.
What I would suggest is that you focus on getting the entity to work with just open and closed (exclude moving). Once that has been achieved, you can experiment with ways to report an intermediate state.