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
71.25k stars 29.86k forks source link

Template not evaluating correctly? Greater than #2623

Closed jwl17330536 closed 8 years ago

jwl17330536 commented 8 years ago

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):

root@automation:/var/opt/home-assistant# cat .HA_VERSION 0.24.1

Python release (python3 --version):

root@automation:/var/opt/home-assistant# python3 --version Python 3.4.2

Component/platform:

sensor / template

Description of problem:

Comparing outside temperature to that of indoor temperature. If outside is greater than indoor then "warmer" else "cooler".

Expected:

I would expect 105 > 79 and result in "warmer" (see attached image) screen shot 2016-07-25 at 3 00 36 pm

Problem-relevant configuration.yaml entries and steps to reproduce:

  - platform: template
    sensors:
      template_outside_vs_upstairs_temp:
        value_template: "{% if states.sensor.upstairs_temperature_2.state > states.sensor.upstairs_temperature.state %}warmer{% else %}cooler{%endif %}"

Traceback (if applicable):

Additional info: I don't think that it is related, but with the above yaml code I cannot start hass. I'm seeing:

Jul 25 14:50:22 automation hass[8732]: WARNING:homeassistant.components.sensor.template:UndefinedError: 'None' has no attribute 'attributes'

EDIT: This error below is not related in any way! I found my problem that caused this. After many lines repeating hass eventually fails trying to initialize an automation rule that is looking for the state of above sensor_template

Jul 25 14:50:33 automation hass[8732]: ERROR:homeassistant.bootstrap:Error during setup of component automation
Jul 25 14:50:33 automation hass[8732]: Traceback (most recent call last):
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 150, in _setup_component
Jul 25 14:50:33 automation hass[8732]: if not component.setup(hass, config):
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/homeassistant/components/automation/__init__.py", line 105, in setup
Jul 25 14:50:33 automation hass[8732]: success = (_setup_automation(hass, config_block, name, config) or
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/homeassistant/components/automation/__init__.py", line 116, in _setup_automation
Jul 25 14:50:33 automation hass[8732]: action = _process_if(hass, config, config_block, action)
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/homeassistant/components/automation/__init__.py", line 173, in _process_if
Jul 25 14:50:33 automation hass[8732]: checks.append(condition.from_config(if_config))
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/homeassistant/helpers/condition.py", line 34, in from_config
Jul 25 14:50:33 automation hass[8732]: return factory(config, config_validation)
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/homeassistant/helpers/condition.py", line 40, in and_from_config
Jul 25 14:50:33 automation hass[8732]: config = cv.AND_CONDITION_SCHEMA(config)
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/voluptuous.py", line 355, in __call__
Jul 25 14:50:33 automation hass[8732]: return self._compiled([], data)
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/voluptuous.py", line 655, in validate_dict
Jul 25 14:50:33 automation hass[8732]: return base_validate(path, iteritems(data), out)
Jul 25 14:50:33 automation hass[8732]: File "/var/opt/home-assistant/lib/python3.4/site-packages/voluptuous.py", line 489, in validate_mapping
Jul 25 14:50:33 automation hass[8732]: raise MultipleInvalid(errors)
Jul 25 14:50:33 automation hass[8732]: voluptuous.MultipleInvalid: not a valid value for dictionary value @ data['conditions'][0]['condition']
jwl17330536 commented 8 years ago

After hitting submit my Nest switched over to use a different weather underground station, which resulted in a drastic change that took the outside temperature below 100. Now that it is below 100 I noticed that it is evaluating 95 is less than 80. Same code from the image above, but with different results which should have been the same.

screen shot 2016-07-25 at 3 12 25 pm

Side note: Anyone have any idea how to ensure that my Nest uses a correct station??? When it jumps to one certain station I always get between 10 and 15 degrees higher than all of the surrounding stations!

kellerza commented 8 years ago

Can you try to wrap both sensor statements with float()?

i.e. {% if float(x.x.x.state) > float(x.x.x.state) %}

jwl17330536 commented 8 years ago

Sorry for the delay. Never had time to do this while the temp was above 100 again.

That works!

screen shot 2016-07-27 at 2 45 53 pm

kellerza commented 8 years ago

Glad its working!

Hope you get your Nest pinned to a weather station.