Possible to use template in for-condition?

Hi,

I’m trying to automate my sunblinds. I have a bh1750 light sensor working via MySensors, which works fine. Also I use the darksky component to determine the cloud coverage. But now I’m stuck with the blind-up automation. I want the blinds go up when the light level is below a specific value for a particular time, which depends on the cloud coverage. So I tried the following:

- id: covers_up_center_right
  alias: Zonneschermen midden en rechts omhoog
  trigger:
  - platform: sun
    event: sunset
  - platform: numeric_state
    entity_id: sensor.relay_temp_light_55_3
    below: 1500
    for: '{{ (30 - states.sensor.dark_sky_cloud_coverage*0.3) | int}'
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ (states.sun.sun.attributes.azimuth > 163) and (states.sun.sun.attributes.azimuth < 343) }}'
      - condition: template
        value_template: '{{ ((as_timestamp(now()) - as_timestamp(states.automation.zonneschermen_midden_en_rechts_omhoog.attributes.last_triggered)) / 60) | int > 20 }}'
  action:
  - service: cover.close_cover
    data:
      entity_id: cover.zonnescherm_midden
  - service: cover.close_cover
    data:
      entity_id: cover.zonnescherm_rechts

This doesn’t work, because the for-condition in the trigger doesn’t support templates as far as I know. But is there a possibility to make this work? Or an alternative for the for-condition which supports templates?

Thanks in advance.

You could try using a template trigger instead of a numeric state trigger. However comparing the .last_changed attribute to now() won’t work.

You might be better off triggering on a state change of sensor.relay_temp_light_55_3 and putting the time since last changed in the conditions as a template condition.

Try this as for:

'{{ 30 - states('sensor.dark_sky_cloud_coverage') | int * 0.3 }}'

Thanks to both for reply. Solution of Dielee doesn’t work; validator says: expected int, got none.
By the way, I think I stop using the darksky sensor, since the cloud coverage isn’t accurate with actual cloud coverage. (Still says 100%, I’m sure it isn’t dat value at the moment.) I think I have a condition which detects for high light intensitiy values in the previous 10 minutes or so which prevent the sunblinds go up and down with fluctuating lux values.

Thanks for thinking along.

You cannot template in the for field. Templates are only allowed in specific fields in the configuration. A good rule of thumb is “Does the field name or parent field name contain the word template?” If the answer to that quest is no, chances are you cannot template there.