Wemo switch question

FWIW, you could turn those two “simpler” automations into one more compact automation that uses service_template:

- id: pump
  alias: Pump
  trigger:
    platform: state
    entity_id: sun.sun, sensor.yr_symbol
  action:
    service_template: >
      {% if states('sun.sun') == 'above_horizon' and
            states('sensor.yr_symbol') in ['1', '2'] %}
        switch.turn_on
      {% else %}
        switch.turn_off
      {% endif %}
    entity_id: switch.courtney_box_fan_

Be aware that the actions will run whenever either sun.sun or sensor.yr_symbol changes in any way (i.e., not just their states, but also their attributes, and sun.sun’s elevation and azimuth attributes change quite often.) But, the switch services do optimize a bit - i.e., trying to turn on a switch that is already on does nothing. Same for turning off. So, depending on what else you have HA doing, you can go with this automation that is a bit more compact, or you can go with the two “simpler” but less compact automations, which also happen to be more efficient (because they only run when the actual states of the sensors change accordingly.)

If it were me, I’d probably go with this last automation (that uses service_template.) BTW, I also wrote it so that you can easily add other sensor.yr_symbol values if you find other ones when you want the pump to run.

Can anybody see anything wrong with this automation?

- id: pump
  alias: Pump
  trigger:
    platform: state
    entity_id: sun.sun, sensor.yr_symbol
  action:
    service_template: >
      {% if states('sun.sun') == 'above_horizon' and
            states('sensor.yr_symbol') in ['1', '2', '3', '4', '40', '46'] %}
        switch.turn_on
      {% else %}
        switch.turn_off
      {% endif %}
    entity_id: switch.pool_heater

Basically I want the switch to turn on if the weather symbol is at 1,2,3,4,40 & 46 but only if the sun is above the horizon.

I see the automation gets triggered but the switch doesn’t turn on. If i manually turn it on it goes off in less then a minute.

Thanks in advance

I just tried the expression in your if statement in the template editor and it evaluated to true (because the sun’s up and yr_symbol is 3.) So this should work, unless yr_symbol is not one of those values. When the switch goes off, I’d suggest entering the expression in the template editor to see if it is indeed false.

BTW, sun.sun updates itself every 30 seconds (mostly to recalculate the elevation), so that explains why the switch goes off in less than a minute.