'Render template with value exposed.
If valid JSON will expose value_json too.
This method must be run in the event loop.'

def async_render_with_possible_json_value(self, value, error_value=_SENTINEL):

    self._ensure_compiled()
    variables = {'value': value}
    try:
        variables['value_json'] = json.loads(value)
    except ValueError:
        pass
    try:
        return self._compiled.render(variables).strip()
    except jinja2.TemplateError as ex:
        _LOGGER.error('Error    parsing    value:    %s    (value:    %s,    template:    %s)', ex, value, self.template)
        return (value if (error_value is _SENTINEL) else error_value)
