Error using input_slider as trigger value

Hi ,

I am just starting to use hass and trying some coding but for some reason itstill won’t work. I’ve tried now all options I could think off …

I am trying to setup an action for a windscreen. The test screen automation should be trigger by the gust wind and compared to a value which I set with a input_slider. For the moment I use an input_boolean ‘screen_out’ to set with the automation.

input_slider:
  wind_open_lim:
    name: 'open at winds lower than (km/h):'
    initial: 20
    min: 5
    max: 30
    step: 1
  wind_close_lim:
    name: 'close at winds higher than (km/h):'
    initial: 30
    min: 20
    max: 40
    step: 1



input_boolean:
  screen_out:
    name: screen boolean
    initial: off



automation:
  - alias: 'open screens'
    trigger:
      platform: numeric_state
      entity_id: sensor.pws_wind_gust_kph
      value_template: '{{ float(states.sensor.pws_wind_gust_kph.state) }}'
      below: >-
        {%- if states.input_slider.wind_open_lim is undefined -%}
        5
        {%- else -%}
        "{{ states.input_slider.wind_open_lim.state | float }}"
        {%- endif -%}
    condition:
      condition: and      
      conditions:
       # - condition: template 
       #   value_template: '{{ (states("sensor.pws_wind_gulider.wind_open_lim") | float) }}'    
        - condition: sun
          after: sunrise
          before: sunset
        - condition: state
          entity_id: input_boolean.screen_out
          state: 'off'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.screen_out

It seems to be in the part `` “{{ states.input_slider.wind_open_lim.state | float }}”`

The error :
expected float for dictionary value @ data[‘trigger’][0][‘below’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 142).

line 142 refers to “automation:”

I think I’ve used all kind of options such as:

  • states.input_slider.wind_open_lim.state
  • states(input_slider.wind_open_lim.state)
  • states(input_slider.wind_open_lim)
  • ‘…’
    -"…"

Also I wonder when to use the "… " or ‘…’ and {%if …%} or {%if- … -% }. Any good links where more information about such items can be found?

What should I modify to get it working and why?

Thanks

You cannot use a template in before, that’s what your error is about.

Try converting this numeric_state trigger into a template trigger. Btw, if you defined an initial value for the input_slider, it will most probably never be undefined.

Something like this (not tested):

automation:
  trigger:
    platform: template
    value_template: "{% if float(states.sensor.pws_wind_gust_kph.state) < float(states.input_slider.wind_open_lim.state) %}true{% endif %}"

Let us know how it goes.

Thanks pplucky,

That did the trick. Now I can continue playing…

I included an initial value thus indeed the error checking is not needed. I did it to see if it would resolve the error.

You mention that I used a template ‘in before’ which is causes the error . If I understand correctly, do you mean that below: or platfrom: numeric_state does not allow the use {%if …% } statements?

Yep, that’s my understanding.

I continued the testing and got a bit further and seemded to work, without errors but only for a short time. I now get a bunch of errors which I’m not able traceback as they do not refer to a line in the configuration file. Do you pplycky or someone else have an idea?

thanx

The code that I’m using:

homeassistant:
# Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 51.926393
  longitude: 4.4563823
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 1
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Amsterdam


mqtt:
  broker: IP RPI
  port: PORT
  client_id: ID
  username: USER
  password: PASS


input_slider:
  wind_open_lim:
    name: 'open at winds lower than (km/h):'
    initial: 25
    min: 5
    max: 40
    step: 1
  wind_close_lim:
    name: 'close at winds higher than (km/h):'
    initial: 30
    min: 1
    max: 40
    step: 1
  buien_lim:
    name: 'close when rain is more than (mm/h):'
    initial: 0.1
    min: 0.1
    max: 2
    step: 0.1
  temp_lim:
    name: 'open when temp will be more than (C):'
    initial: 19
    min: 15
    max: 30
    step: 1

input_boolean:
  screen_out:
    name: screen boolean
    initial: off
 

sensor:
# get some weather data
  - platform: darksky
    api_key: KEY
    monitored_conditions:
      - temperature
      - precip_intensity
      - precip_probability
      - wind_speed
      - temperature_max
      - precip_intensity_max
    units: si
    update_interval: 
      minutes: 10

# buienradar did result in some timer out of sync so disabled it for the moment	  
#  - platform: buienradar
#    timeframe: 60
#    monitored_conditions:
##      - windgust
#      - precipitation_forecast_average
#      - precipitation
      

  - platform: wunderground
    api_key: KEY
    monitored_conditions:
      - temp_c
      - temp_high_1d_c
      - precip_1d_mm
      - precip_1d
      - precip_today_metric
      - wind_degrees
      - wind_kph
      - wind_gust_kph
      - wind_gust_1d_kph

  - platform: template
    # some sensors to get the actual reading of the sliders
    sensors:
      show_wind_close:
        friendly_name: 'show wind closing limit'
        value_template: "{{ (float(states.input_slider.wind_close_lim.state)) }}"
      show_wind_open:
        friendly_name: 'show wind open limit'
        value_template: "{{ (float(states.input_slider.wind_open_lim.state)) }}"
      show_precip_lim:
        friendly_name: 'show precipitation limit'
        value_template: "{{ (float(states.input_slider.buien_lim.state)) }}"        
      show_temp_lim:
        friendly_name: 'show temperature limit'
        value_template: "{{ (float(states.input_slider.temp_lim.state)) }}"                
      screenstatus:
        friendly_name: 'screen status'
        value_template: >
          {% if is_state('input_boolean.screen_out', 'on') %}
            Open
          {% else %}
            Closed
          {% endif %}  
       

group:
  #group the windscreen status and settings
  screenstatus:
    name: screen group
    entities:
      - sensor.screenstatus
      - input_boolean.screen_out
      - input_slider.wind_open_lim
      - sensor.show_wind_open 
      - input_slider.wind_close_lim   
      - sensor.show_wind_close      
      - input_slider.temp_lim
      - sensor.show_temp_lim
      - input_slider.buien_lim
      - sensor.show_precip_lim 

  #present the weather data
  #some monitored conditions from the weather were not recognised 
  #as sensors and therefore not listed here
  wundergrndst:
    name: 'wunderground weather data'
    entities:
      - sensor.pws_temp_c
      - sensor.pws_temp_high_1d_c
      - sensor.pws_wind_degrees
      - sensor.pws_wind_kph
      - sensor.pws_wind_gust_kph
      - sensor.pws_wind_gust_1d_kph
#  buienradar:
#    name: 'buienradar weather data'
#    entities:
##      - sensor.br_windgust
#      - sensor.br_precipitation_forecast_average
#      - sensor.br_precipitation
  darksky:
    name: 'dark sky weather data'
    entities:
      - sensor.dark_sky_temperature
      - sensor.dark_sky_precip_intensity
      - sensor.dark_sky_precip_probability
      - sensor.dark_sky_wind_speed
      - sensor.dark_sky_temperature_max
      - sensor.dark_sky_precip_intensity_max

  

# included in hte next template platforms the if statement with sensor = nothing as float covers all except when sensor is nothing    
        
automation:

# open the screens
  - alias: 'open screens'
    trigger:
      # open screens when temp this day is higher than set limit
      - platform: template
        value_template: "{% if states.sensor.pws_temp_high_1d_c is undefined %}false{% elif float(states.sensor.pws_temp_high_1d_c.state,0.0) > float(states.input_slider.temp_lim.state) %}true{% else %}false{% endif %}"
      # open screens when temp this day is higher than set limit
      - platform: template
        value_template: "{% if states.sensor.pws_temp_c.state is undefined %}false{% elif float(states.sensor.pws_temp_c.state,0.0) > float(states.input_slider.temp_lim.state) %}true{% else %}false{% endif %}"

    condition:
      condition: and
      conditions:
        - condition: sun
          after: sunrise
          before: sunset
        - condition: state
          entity_id: input_boolean.screen_out
          state: 'off'
        - condition: template
          value_template: "{% if states.sensor.pws_wind_gust_kph.state is undefined %}false{% elif float(states.sensor.pws_wind_gust_kph.state,states.input_slider.wind_open_lim.state+1) < float(states.input_slider.wind_open_lim.state) %}true{% else %}false{% endif %}"
  
#removed buienradar in bugtracking 
#        - condition: template
#          value_template: "{% if states.sensor.br_precipitation_forecast_average is undefined %}false{% elif float(states.sensor.br_precipitation_forecast_average.state) < float(states.input_slider.buien_lim.state) %}true{% else %}false{% endif %}"
#        - condition: template
##          value_template: "{% if float(states.sensor.br_precipitation.state) < float(states.input_slider.buien_lim.state) %}true{% endif %}"
#          value_template: "{% if states.sensor.br_precipitation is undefined %}false{% elif float(states.sensor.br_precipitation.state) < float(states.input_slider.buien_lim.state) %}true{% else %}false{% endif %}"

    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.screen_out


#close the screens  
  - alias: 'close screens' 
    trigger:
      - platform: sun
        event: sunset
      #close in case wind is too high
      - platform: template
        value_template: "{% if states.sensor.pws_wind_gust_kph.state is undefined %}false{% elif float(states.sensor.pws_wind_gust_kph.state,0.0) > float(states.input_slider.wind_close_lim.state) %}true{% else %}false{% endif %}"
      - platform: template
        value_template: "{% if states.sensor.pws_wind_kph.state is undefined %}false{% elif float(states.sensor.pws_wind_kph.state,0.0) > float(states.input_slider.wind_close_lim.state) %}true{% else %}false{% endif %}"

#close in case it rains. removed during bugtracking
#      - platform: template
#        value_template: "{% if states.sensor.br_precipitation_forecast_average is undefined %}false{% elif float(states.sensor.br_precipitation_forecast_average.state) > float(states.input_slider.buien_lim.state) %}true{% else %}false{% endif %}"
#      - platform: template
#        value_template: "{% if states.sensor.br_precipitation is undefined %}false{% elif float(states.sensor.br_precipitation.state) > float(states.input_slider.buien_lim.state) %}true{% else %}false{% endif %}"

    condition:
      - condition: state
        entity_id: input_boolean.screen_out
        state: 'on'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.screen_out 



# Enables the frontend
frontend:

# Enables configuration UI
config:

http:

updater:

# Discover some devices automatically
discovery:
  ignore:
    - samsung_tv

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

recorder:
  purge_days: 8


and the errors

2017-08-03 23:19:03 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2017-08-03 23:19:46 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

and this one is present with regular intervals of about 5 minutes sometimes double

2017-08-03 23:43:25 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_track_state_change.<locals>.state_change_listener(<Event state_...131668+02:00>>) at /srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/event.py:60
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/event.py", line 80, in state_change_listener
    event.data.get('new_state'))
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 247, in async_run_job
    target(*args)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/event.py", line 100, in template_condition_listener
    template_result = condition.async_template(hass, template, variables)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/condition.py", line 296, in async_template
    value = value_template.async_render(variables)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 101, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/sandbox.py", line 427, in call
    return __context.call(__obj, *args, **kwargs)
TypeError: forgiving_float() takes 1 positional argument but 2 were given
2017-08-03 23:49:47 ERROR (MainThread) [homeassistant.core] Error doing job: Fatal read error on socket transport
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/selector_events.py", line 582, in _read_ready
    data = self._sock.recv(self.max_size)
TimeoutError: [Errno 110] Connection timed out
```