I have just changed my old MQTT cover code to the newer format but the new format does not allow for templated icons to show the current cover status. If I use a normal icon config I don’t get a dynamic icon relating to the cover status.
This old code is no longer valid with the new way of configuring MQTT covers as they only allow for a static icon: parameter.
I actually receive all of the Paradox Alarm system status / state changes on that topic, so all sensors changing etc.
The cover entity doesn’t actually need that state_topic since it should just use it’s status based on the template sensor, however if I comment out the state_topic line the cover throws an error and won’t load in HA which is why I put it in there (docs do say it’s optional hence it passes config check when commented out)
error:
Manually configured MQTT sensor(s) found under platform key ‘sensor’, please move to the mqtt integration key, see MQTT Sensor - Home Assistant
2022-06-16 04:52:15 ERROR (MainThread) [homeassistant.config] Invalid config for [cover]: ‘value_template’ must be set together with ‘state_topic’… Got OrderedDict([(‘name’, ‘Garage Door’), (‘device_class’, ‘garage’), (‘value_template’, “{{is_state(‘binary_sensor.paradox_z3_garage_door’, ‘on’)}}”), (‘command_topic’, ‘paradoxdCTL/in’), (‘payload_open’, ‘{ “password”: “xxxx”, “Command”: “PGM_ON”, “Subcommand”: “2” }’), (‘payload_close’, ‘{ “password”: “xxxx”, “Command”: “PGM_ON”, “Subcommand”: “2” }’), (‘payload_stop’, ‘{ “password”: “xxxx”, “Command”: “PGM_ON”, “Subcommand”: “2” }’)]). (See /config/packages/garage_door.yaml, line 6).
Yeah if you want to use a value template you have to have a state topic. It’s just that your value template is resolving to true or false when the default values it is looking for are: closed and open. Either specify the state_open: false and state_closed: true options (See my screenshot above) or use this value template:
value_template: "{{'open' if is_state('binary_sensor.paradox_z3_garage_door', 'on') else 'closed'}}"
Which seemed to be what I should have used from the start, but it still didn’t work.
Your template above works perfectly, thanks mate.
EDIT: just to clarify, Tom’s template works to resolve the cover status yet the config still requires a state_topic be configured which seems like a bug given that the state_topic in this case is not helping in any way but needs to have something written in it for the sake of the component loading.
Well no, it’s not a bug. If you use a value_template the integration expects to receive something on the state_topic. The only way to not include a state topic is to not include a value_template. Then the integration defaults to optimistic mode.
I think I spoke too soon… After opening and closing the garage door a few times the cover entity is showing open instead of closed.
Then why can’t we simply use the value_template which uses the status from another entity rather than getting that status via MQTT? It seems those two things (value_template vs state_topic) are trying to achieve the same thing…?
I’m thinking I’ll actually try swapping this for a template cover instead and just use service calls for sending out the MQTT commands, it might be easier for my use case.
value_template: "{{'closed' if is_state('binary_sensor.paradox_z3_garage_door', 'on') else 'open'}}"
It’s an MQTT cover. It was written to expect a state on a state topic. Interpreting that state can be done with a value_template and two other options that define the open and closed messages.
I swapped the MQTT cover for a template cover, basically using my old MQTT cover code (the deprecated method) and so far it looks to be working. I’ll run some tests.