home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.94k stars 29.02k forks source link

Developer Tools Template Editor returning incorrect attribute type #46198

Closed tomlut closed 3 years ago

tomlut commented 3 years ago

The problem

The developer tools template editor is returning an incorrect type for attributes. e.g. From the developer tools states menu, sensor.json_lounge_aircon returns this:

state: '0'
mode: '4'
temp: '19'
fan: '160'
aux: '0'
roomt: '25.76'
friendly_name: JSON Lounge Aircon

The attribute temp is clearly a string, yet the template editor displays the result shown in Figure 1. in Additional Information below (I cant attach images in this text box).

Testing for a number in the template returns the expected result. See Figure 2. below.

What is version of Home Assistant Core has the issue?

core-2021.2.1

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

Developer Tools Template Editor

Link to integration documentation on our website

https://www.home-assistant.io/docs/tools/dev-tools/#template-editor

Example YAML snippet

# Put your YAML below this line

Anything in the logs that might be useful for us?

# Put your logs below this line

Figure 1.

Screenshot_2021-02-08 Developer Tools - Home Assistant

Figure 2.

Screenshot_2021-02-08 Developer Tools - Home Assistant2

probot-home-assistant[bot] commented 3 years ago

Hey there @phracturedblue, @tetienne, mind taking a look at this issue as its been labeled with an integration (template) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

github-actions[bot] commented 3 years 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.

tomlut commented 3 years ago

Still an issue in core 2021.6.6

frenck commented 3 years ago

It is correct actually, as templates represent an evaluated result. Thus the result is indeed a number.

tomlut commented 3 years ago

This is the attribute temp containing a string:

temp: '19'

This is the attribute temp containing a number:

temp: 19

Both return the type number in the template editor when using state_attr(). This has confused a few people using the template editor to debug templates.

If there is no way around it I'll close the issue and just be aware of it when helping others.

frenck commented 3 years ago

Well, attributes actually support native types, but it is up to the integration to provide them. In this case, it provides strings.

Nevertheless, the output of a template is always evaluated, thus it gets converted in the matching native type.

I agree, in this case, it is confusing and would help if the integration used native typing for its attributes (making them easier to use as well).

tomlut commented 3 years ago

In my case it was the core restful sensor integration, but to be fair it's actually my old Air-conditioning unit's bad json typing response that's at fault. Fortunately I'm not using it any more.