home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
3.8k stars 2.6k forks source link

Home assistant automatically capitalising known list of states in if statement, causing if statement to be false #13715

Closed Jordenjj closed 7 months ago

Jordenjj commented 1 year ago

Checklist

Describe the issue you are experiencing

As shown below, when using the new (super handy) dropdown menu of known states, the states seem to be autocapitalized:

Screenshot 2022-09-13 at 11 47 26

While the actual states are not:

Screenshot 2022-09-13 at 11 46 43

Resulting in false if statements, that are expected to be true:

Screenshot 2022-09-13 at 11 48 42

Describe the behavior you expected

Drop down menu of expected states, should be true to the capitalisation of the actual states.

Steps to reproduce the issue

  1. Create automation using if statement
  2. Use auto dropdown to select a state
  3. Check if condition becomes true whether the if statement thinks the same

What version of Home Assistant Core has the issue?

core-2022.9.2

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

No response

Which operating system are you using to run this browser?

No response

State of relevant entities

At least person home/not_home state, expectedly much more.

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

No response

ildar170975 commented 1 year ago

You are wrong. Displayed names differ from actual names. May depend on a device_class too.

Examples:

  1. Internally binary_sensor, input_boolean, switch entity have states on / off - but in UI you see On / Off.
  2. unavailable -> Unavailable.
  3. off -> Disconnected.
  4. not_home -> Away.
Jordenjj commented 1 year ago

You are wrong. Displayed names differ from actual names. May depend on a device_class too.

Examples:

  1. Internally binary_sensor, input_boolean, switch entity have states on / off - but in UI you see On / Off.
  2. unavailable -> Unavailable.
  3. off -> Disconnected.
  4. not_home -> Away.

I fail to understand why I'm wrong, suggested states without caps will always be better since it can't get the wrong comparison don't you think?

ildar170975 commented 1 year ago

I do not see a wrong comparison. Assume there is a device_tracker.maria entity which may be internally "home", "not_home". Then your templates in automations may be:

{% if is_state('device_tracker.maria','home') %}
{{ ...}}
{% elif is_state('device_tracker.maria','not_home') %}
{{ ...}}
{% endif %}

and you will see in UI values like "Home" & "Away".

Jordenjj commented 1 year ago

I do not see a wrong comparison. Assume there is a device_tracker.maria entity which may be internally "home", "not_home". Then your templates in automations may be:

{% if is_state('device_tracker.maria','home') %}
{{ ...}}
{% elif is_state('device_tracker.maria','not_home') %}
{{ ...}}
{% endif %}

and you will see in UI values like "Home" & "Away".

I think you're talking about different things. Check the trace screenshot above, it throws false when it should be true when the UI text is used.

Im not talking about the UI displaying it, im talking about the UI suggestions being autocapitalised in automations causing the automation not to work as expected.

ildar170975 commented 1 year ago

Im not talking about the UI displaying it, im talking about the UI suggestions being autocapitalised in automations causing the automation not to work as expected.

Here is a screenshot from "Create automation" -> "Triggers": изображение The dropdown list contains possible states for device_tracker - which are "UI versions" of "real internal values".

As for me - I would leave all these "UI versions" for Lovelace only and use "entity_ids" & "real internal values" everywhere else. In this case there would be a real entity's "entity_id" instead of "IPhone 5S" (got plenty of entities with this friendly name) and real values "home / not_home / ..."in dropdown list.

Jordenjj commented 1 year ago

The dropdown list contains possible states for device_tracker - which are "UI versions" of "real internal values".

I get that... Again, different thing.

The problem is that it fills the backend with the caps as well which doesn't work.

ildar170975 commented 1 year ago

The problem is that it fills the backend with the caps as well which doesn't work.

What do you mean by "fills the backend"?

Again, different thing.

I am not getting your point.

Jordenjj commented 1 year ago

The point is, using the drop down menu doesn't work, since it will put "Home" in the yaml, and the if statement will not work since it will say expected: home, got: Home as seen in the trace above.

ildar170975 commented 1 year ago

This is very strange what you are observing.

I do not observe the same errors. Create a new automation: trigger: if device_tracker changes from Home to Away -> notify.

image

Go to Yaml mode - it creates a correct code:

description: ""
trigger:
  - platform: state
    entity_id:
      - device_tracker.vmmac
    from: home
    to: not_home
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: mac is away
mode: single

Switch back to UI mode - these "Home" & "Away" are replaced: image

And this automation works.


Or add "if .. then ..." statement: image which generates this yaml:

alias: test_mac_away
description: ""
trigger:
  - platform: state
    entity_id:
      - device_tracker.vmmac
    from: home
    to: not_home
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: Mac is away
  - if:
      - condition: state
        entity_id: device_tracker.vmmac
        state: home
    then:
      - service: notify.persistent_notification
        data: {}
mode: single
confuserated commented 1 year ago

I agree,

I'm seeing the same behaviour (using Safari) when selecting visual editor in automations, in my case the selectable states are "On, Off, Unavailable, Unknown" for a configured boolean, but when choosing one of the states suggested the automation doesn't work, since it populates the YAML with a capitalised On (for instance) but the entity returns an uncapitalised "on", thus the statement returns "false" when I would expect it to return "true" and the automation effectively fails.

Spent a whole three days trying to work out why my automations weren't working when it logically should, using the provided tools, very frustrating...

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

confuserated commented 1 year ago

I found that it was card-mod causing the problems for me, removing card-mod made everything work as expected.

ildar170975 commented 1 year ago

Magic, how card-mod could auto-capitalize letters ))))))))))))

confuserated commented 1 year ago

Absolutely, but that’s what I have observed. No changes were made except to remove card-mod, but the problem is now resolved for me. I’ve opened an issue for card-mod but I don’t hold out much hope for it to even be looked at as the list of issues is quite long for it.

ildar170975 commented 1 year ago

If you install card-mod - will the issue return? Could you test it?)

I am asking because card-mod cannot interfere in a SUCH way. As for the issue - I am afraid it will be not resolved since there is no detailed info how to reproduce the issue.

confuserated commented 1 year ago

I’ll give it a go

confuserated commented 1 year ago

I gave it a go and saw the following:

After uninstalling card-mod the problem immediately went away and now when I alter or create an automation with the same entities and attributes it works ok.

I re-installed card-mod and the problem did not come back...

I've tried adding new automations with the same entities and attributes to monitor and everything works as expected.

I can't understand why this would be as nothing else has changed.

I'm at a loss to explain what is happening here, but, I do have a backup I could use to test when I was getting the problem and could go through this process again but is it worthwhile?

BillyFKidney commented 1 year ago

I am experiencing this same issue, it took me a while to debug:

Manually written YAML snippet:

      - condition: not
        conditions:
          - condition: state
            entity_id: sensor.eagle_200_meter_power_demand
            state: unavailable
        alias: Current Power Demand Available?
image

Convert to visual editor:

image

Click dropdown, text is capitalized, select value (DO NOT SAVE):

image

When the entity is unavailable while creating the automation it would save it "Unavailable"

github-actions[bot] commented 10 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 7 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.