Trying to trigger a switch using weather entity

I have all my switches working and am trying to figure out how to trigger a water valve switch for a mister for my animals when the weather gets hot.

Sudo code:

If weather.temperature > 75 F Then
  turn on water switch for 1 minute
  delay 30 min and repeat until
    weather.temperature < 75 F

Here’s the info from my states UI

weather.hop_house   	sunny	
temperature: 76.3
humidity: 36
pressure: 1014.6
wind_bearing: 240.5
wind_speed: 7.6
attribution: Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.
friendly_name: HOP House

I don’t see this entity appear in any trigger options anywhere. I was reading a post about templates but haven’t ventured there yet. I also discovered that I may get caught up in triggering this continually and may need a binary switch in a template. I’m also not sure that the Norwegian Meteorological Institute is the best place to get my weather forecast info…

Any pointers appreciated.

Jeff

You can make a binary sensor using templates and pull the data from your entity as an attribute.

Then it should work like a normal numeric automation

I’ll give you the properly formatted basic functionality but you will have to add in the details:

alias: the name of the automation
trigger:
  platform: time_pattern
  minutes: '/30'
condition:
  platform: template
  value_template: '{{ state_attr('weather.hop_house', 'temperature') | int > 75 }}'
action:
  - service: switch.turn_on
    entity_id: switch.your_water_switch
  - delay: '00:01:00'
  - service: switch.turn_off
    entity_id: switch.your_water_switch

What this should do is every 30 minutes it will check to see if the temperature attribute of the sensor is over 75 degrees and will turn on the water switch, wait 1 minute and then turn off the water switch.

It will run every 30 minutes 24 hours a day so If you don’t want that then you will need to add in a time of day condition as well.

Interesting. Ok, I added this to automations.yaml

- id: '1567518945323'
  alias: Turn Water Valave on when temp above 75
  trigger:
    platform: time_pattern
    minutes: '/30'
  condition:
    platform: template
    value_template: '{{ state_attr('weather.hop_house', 'temperature') | int > 75 }}'
  action:
    - service: switch.turn_on
      entity_id: switch.water
    - delay: '00:01:00'
    - service: switch.turn_off
      entity_id: switch.water

But I get this error in configurator:

can not read an implicit mapping pair; a colon is missed at line 86, column 86:
     ... ', 'temperature') | int > 75 }}'
                              ^

And this error when restarting

Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/automations.yaml", line 85, column 5
expected <block end>, but found '<scalar>'
  in "/config/automations.yaml", line 86, column 37

I read up on automation templates and the formatting looked ok to me.

Jeff

I see what I did wrong…:roll_eyes:

I needed different quotation mark types inside and outside of the template.

Sorry for the rookie mistake. As long as I’ve been doing this I should have caught the mistake.

try this for the value_template line:

value_template: "{{ state_attr('weather.hop_house', 'temperature') | int > 75 }}"

Now I get this error

Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->condition->0->platform. (See /config/automations.yaml, line 78).

Researching this error, I see something about conditions in this post,

condition:
    condition: template
    value_template:  '{{states.sensor.humidity.state | float > 71.00}}'

I tried that and got all kinds of new errors. But now this is way out of my depth…

Is there not a more friendly way to do this?

Jeff

Your error looks like an indentation error. Can you share the complete yaml code for this automation as you have it now?

- id: '1567518945323'
  alias: Turn Water Valave on when temp above 75
  trigger:
    platform: time_pattern
    minutes: '/30'
  condition:
    platform: template
    value_template: ”{{ state_attr('weather.hop_house', 'temperature') | int > 75 }}”
  action:
    - service: switch.turn_on
      entity_id: switch.water
    - delay: '00:01:00'
    - service: switch.turn_off
      entity_id: switch.water

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

I finally got it to load without errors. It was in the condition statement.

- id: '1567518945323'
  alias: Turn Water Valave on when temp above 75
  trigger:
  - minutes: /30
    platform: time_pattern
  condition:
  - condition: template
    value_template: ”{{ state_attr('weather.hopi_house', 'temperature') | int > 75
      }}”
  action:
  - data:
      entity_id: switch.water
    service: switch.turn_on
  - delay: 00:02:00
  - data:
      entity_id: switch.water
    service: switch.turn_off

Oops. Sorry about that one too. :frowning: