Value template two text values not equal as a condition

How do I do this both != and <> don’t seem to work

  condition:
  - condition: template
    value_template: "{{ ( states("input_text.commute_start_zone" ) != ( states("device_tracker.pauls_iphone" ) }}"

Both values are ascii text, Maybe a different route will be required?

1 Like

Pretty sure != is correct in jinja.

Are you sure that they are the same type? Googling “compare strings in jinja” finds some stack exchange posts that suggested that data typing could be the problem.

Looked at it further (should get back to work!)

It soon gets beyond me, but this page is fairly thorough: https://www.home-assistant.io/docs/configuration/templating/

One value is an input_text, the other is a state of my tracker with returns a zone name. They both look to be text to me, but I get an error (might be formatting) when I try to use this.

Have you tried explicitly casting them both as strings?

value_template: "{{ ( states('input_text.commute_start_zone' ) | string != ( states('device_tracker.pauls_iphone' ) | string }}"

1 Like

Have not done that, but sounds like it will work, I’ll try that and report back., thanks!

I think the problem here is incorrect use of quote characters. The quotes inside the template can’t be the same type as the ones that surround the entire template. And the parentheses are off. You need to change it to:

  condition:
  - condition: template
    value_template: "{{ states('input_text.commute_start_zone') != states('device_tracker.pauls_iphone') }}"
3 Likes

Damn. I automatically did that for my reply without spotting the original had double quotes everywhere. Well spotted.

2 Likes

Thanks! makes sense, I copied/pasted from two different areas of my automation.

THANK YOU very much

1 Like

EDIT: Nevermind. This will fire always… change != to == so when both IP are same it will fire now.

Hi All,

I use this condition in HA 0.116.4:

  condition:
    - condition: template
      value_template: "{{ (states('sensor.dsmr_ext_ip')) | string != (states('sensor.external_ip')) | string }}"

Developer tool show me “true” so both are not equal.

But the action after it still fire… Is there a change in templating in 0.116.x ?