Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String "None" is always value none no matter what #50715

Closed
TheEris opened this issue May 16, 2021 · 4 comments
Closed

String "None" is always value none no matter what #50715

TheEris opened this issue May 16, 2021 · 4 comments

Comments

@TheEris
Copy link

TheEris commented May 16, 2021

The problem

When you try to pass "None" as a string in templates (using {{ 'None' }} ) it returns the value None. No matter how you formate it according to docs from Jinja. I've tried {% raw %} None {% endraw %} and {{ 'None' }}.

This template return string "Something" when the X is false, and no value when true. It should return the string "None".

{% set x = true %}
{% if x == true %}
{{ 'None' }}
{% else %}
{{ 'Something' }}
{% endif %}

This is true even if you try to separate the None string into two parts. Like this:

{% set x = true %}
{% if x == true %}
{{ 'No' }}{{ 'ne' }}
{% else %}
{{ 'Some' }}{{ 'thing' }}
{% endif %}

it will return the string "Something" just ok, but the value none if X is true.
Also true for this case:

{% set x = true %}
{% if x == true %}
{{ 'No' }}ne
{% else %}
{{ 'Some' }}thing
{% endif %}

This also applies to the {% raw %}

{% set x = true %}
{% if x == true %}
{% raw %} None {% endraw %}
{% else %}
{% raw %} Something {% endraw %}
{% endif %}

This also returns the value none instead of the string "None".
But this returns string "{{ 'None' }}"

{% set x = true %}
{% if x == true %}
{% raw %} {{ 'None' }} {% endraw %}
{% else %}
{% raw %} {{ 'Something' }} {% endraw %}
{% endif %}

What is version of Home Assistant Core has the issue?

core-2021.5.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

https://www.home-assistant.io/docs/configuration/templating/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@frenck
Copy link
Member

frenck commented May 16, 2021

This is currently a known limitation, we evaluate the output of template back to native types. Which causes this.

@TheEris
Copy link
Author

TheEris commented May 16, 2021

is there a workaround for this? I would like to pass the "None" effect for esphome light in the template.

@frenck
Copy link
Member

frenck commented May 16, 2021

If you call a service for that, you can use a choose to do it without a template in that case.

@TheEris
Copy link
Author

TheEris commented May 16, 2021

that's my workaround for now. I wanted to have a neat single template that handles it in a single go, but this works too.

@TheEris TheEris closed this as completed May 16, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants