Make variable entity_id available to value_template for MQTT binary sensor (#19195)

* MQTT binary_sensor: Make variable `entity_id` available to value_template

* Review comments

* Add testcase
This commit is contained in:
emontnemery 2018-12-14 13:00:37 +01:00 committed by Paulus Schoutsen
parent e886576a64
commit b97f0c0261
3 changed files with 33 additions and 5 deletions

View file

@ -135,7 +135,7 @@ class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
value_template = self._config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
payload = value_template.async_render_with_possible_json_value(
payload)
payload, variables={'entity_id': self.entity_id})
if payload == self._config.get(CONF_PAYLOAD_ON):
self._state = True
elif payload == self._config.get(CONF_PAYLOAD_OFF):