Template variable warning: 'FALSE' is undefined when rendering

Can someone help me with this log error. I am brand new to HA and have researched this for hours. I have messages coming into mqtt mosquito from a weather station and populating correctly in a normal sensor not binary. The specific message I’m having trouble with is a character based and not a number. The message is showing up in HA correctly as {Ok }

What I’m trying to do with the template below is to watch for {Ok } as it comes in and display it as OK on a front end card. If a message comes in with anything but {Ok } I want it to be displayed as LOW. I actually believe this is working but HA is not happy at all in the log. I barely know what I’m doing with coding so any help would be appreciated.

Logger: homeassistant.helpers.template
Source: helpers/template.py:583
First occurred: 1:21:12 PM (30 occurrences)
Last logged: 1:52:27 PM

Template variable warning: ‘FALSE’ is undefined when rendering ‘{% if value|regex_search(’{Ok }’, ignorecase=FALSE)%}OK{% else %}LOW{% endif %}’

The following is in the config yaml:

  • name: “iss”
    state_topic: “iss”
    value_template: ‘{% if value|regex_search(’’{Ok }’’, ignorecase=FALSE)%}OK{% else %}LOW{% endif %}’

In templates the boolean to set arguments should be lowercase, if you use FALSE or False it thinks you are referring to a variable that it can’t find a definition for…

  - name: "iss"
    state_topic: "iss"
    value_template: >
      {% if value|regex_search("{Ok }", ignorecase = false)%}
      OK{% else %}LOW{% endif %}

Drew thanks so much it works perfectly now with no errors. Thanks for the explanation and fix!!!
Greatly appreciated
John

1 Like