Getting state from calender isn't working

Hi

I’ve tried to use both helper calender and local calender in automations but I seem to get weird states no matter what I code.
The automations always turn off, then on again when the calender(s) change state to off.
For some cases it works flawlessly for a while then intermittently the state went to “on” again.
I have had to make an automation to check state ever x minutes not to drown my plants.

alias: Greenhouse drip-irrigation
description: ""
trigger:
  - platform: state
    entity_id:
      - calendar.greenhouse_calendar
    to: "on"
  - platform: state
    entity_id:
      - calendar.greenhouse_calendar
    to: "off"
condition: []
action:
  - service: switch.turn_{{ 'on' if trigger.to_state.state == 'on' else 'off' }}
    target:
      entity_id: switch.sonoff_smartrelay_1
mode: single

another example:

  alias: Greenhouse drip-feed automation
  description: ''
  trigger:
  - platform: state
    entity_id:
    - schedule.wateringschedule_drip_feed
    to: 'on'
    id: 'on'
  - platform: state
    entity_id:
    - schedule.wateringschedule_drip_feed
    to: 'off'
    id: 'off'
	  - platform: state
    entity_id:
    - schedule.wateringschedule_drip_feed
    to: ''
    id: 'off'
  condition: []
  action:
  - service: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.sonoff_smartrelay_1
  mode: single