Trying to include a template sensor as a condition in an automation

hi all,

here is what i am trying to do.

i have my lounge lamps turn on early morning at a set time and this automation is supposed to turn the lights off 45 mins after sunrise unless the cloud cover is greater then 50% according to dark sky.

i have other automatons that turn the lights on and off depending on the cloud cover % through the day and they work perfectly.

here is what i have.

- id: '1542575515584'
  alias: Turn lounge lamps off after sunrise
  hide_entity: true
  trigger:
  - event: sunrise
    offset: 00:45:00
    platform: sun
  condition:
  - platform: template
    value_template: '{{states. sensor.dark_sky_cloud_coverage.state | int < 50}}'
  action:
  - service: switch.turn_off
    entity_id:
    - switch.corner_lamp
    - switch.tall_lamp

when i do this i get errors telling me to check an empty file for errors .
if I hash out the problem

#  condition:
#  - platform: template
#    value_template: '{{states. sensor.dark_sky_cloud_coverage.state | int < 50}}'

everything works except obviously this condition.

what am i doing wrong? how can i get this to work?

i have almost no coding experience and i’m trying to learn this as i go along but this has me totally stumped for about a week now, any help is greatly received.

thank you all in advance.

There is a space after “{{states.”, remove that and try again.
Like this:
value_template: '{{ states.sensor.dark_sky_cloud_coverage.state | int < 50 }}'

hi Pippyn,

thanks for your reply, i missed that. however when i corrected it and clicked on “test config” i got the following error.

Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->condition->0->platform. (See /config/configuration.yaml, line 79). Please check the docs at https://home-assistant.io/components/automation/

line 79 in configuration.yaml reads " group: !include groups.yaml" and groups.yaml is empty.

i’m at a total loss as to whats gone wrong here.

Platform is for trigger, change that to condition. Also, use the states() method so that this won’t error out if the automation fires during startup.

  condition:
  - condition: template
    value_template: "{{ states('sensor.dark_sky_cloud_coverage') | int < 50 }}"

thanks Petro,

that’s it sorted thank you. it was a combination of that and an extra space at the start of another line.