diff --git a/homeassistant/components/sensor/mqtt.py b/homeassistant/components/sensor/mqtt.py index fadf171d15b..c3cc9e3003f 100644 --- a/homeassistant/components/sensor/mqtt.py +++ b/homeassistant/components/sensor/mqtt.py @@ -60,7 +60,7 @@ class MqttSensor(Entity): """A new MQTT message has been received.""" if value_template is not None: payload = value_template.render_with_possible_json_value( - payload) + payload, self._state) self._state = payload self.update_ha_state() diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 03029c369e6..c67f4e62665 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -402,7 +402,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): """Test if callback is safe.""" return isinstance(obj, AllStates) or super().is_safe_callable(obj) -ENV = TemplateEnvironment() +ENV = TemplateEnvironment(undefined=jinja2.StrictUndefined) ENV.filters['round'] = forgiving_round ENV.filters['multiply'] = multiply ENV.filters['timestamp_custom'] = timestamp_custom