Timed Relays - Switches

Hi Friends,

for the second day I am struggling with the setting up Timed Switches for my Irrigation (Sprinklers System).

I have Wemos D1 Mini with Tasmota 6.5.0 + 4 channels relays board.
All for relays are working correctly (with the ON - OFF options).

Now I wanted to add a timer with slider for the switches and here I am going mad!.
The issue is with the state of the switch, error:

ERROR (MainThread) [homeassistant.helpers.script] Error rendering ‘Wylacz zawor glowny’ delay template: UndefinedError: ‘None’ has no attribute ‘state’

My current configuration:
configuration.yaml:

switch:
  - platform: mqtt
    name: "glowny zawor"
    state_topic: "stat/wemos4/POWER1"
    command_topic: "cmnd/wemos4/POWER1"
    qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

slider:
input_number:
  slider1:
    name: Czas spryskiwaczy
    initial: 10
    min: 1
    max: 30
    step: 1

automation.yaml:

  - alias: "Czas spryskiwaczy"
    trigger:
      platform: state
      entity_id: switch.glowny_zawor
      to: 'on'
    action:
      service: homeassistant.turn_on
      entity_id: script.timed_sprinkler

scripts.yaml:

  timed_sprinkler:
    alias: "Ustaw czas spryskiwaczy"
    sequence:
      # Cancel ev. old timers
      - service: script.turn_off
        data:
          entity_id: script.timer_off
      # Set new timer
      - service: script.turn_on
        data:
          entity_id: script.timer_off
  timer_off:
    alias: "Wylacz zawor glowny"
    sequence:
      - delay: '00:00:{{ states.input_slider.slider1.state | int }}'
      - service: homeassistant.turn_off
        entity_id: switch.glowny_zawor

I was trying to add value_template to the switch like this:

value_template: ‘{% if states.switch.glowny_zawor.state %}{{ states.switch.glowny_zawor.attributes.current_activity }}{% endif %}’

But this is not changing anything.
I was also trying with this value_template:
value_template: “{{ states(‘sensor.glowny_zawor’)|float > 0 }}”

Also I was trying to change the switch configuration, like adding:

  • availability_topic: “tele/wemos4/LWT”,
  • state_on , state_off options,
  • any many others,

Can someone please help me with this configuration?
Much appriciated!.

Regards,
Tomasz

The error message concerns the data template for delay.

Error rendering ‘Wylacz zawor glowny’ delay template: UndefinedError: ‘None’ has no attribute ‘state’

      - delay: '00:00:{{ states.input_slider.slider1.state | int }}'

Replace input_slider with input_number.

I do not know, how could I skip this!

Thanks a lot - it’s working! :slight_smile: