Pool pump automation user selectable start time, run time is based on season. tzinfo error

Pump start

 'time-only input_datetime helper called input_datetime.poolpump_start'

Pump stop

I’m using a template sensor to generate a poolpump stop time which is the start time plus a number of hours based on the season. (longer poolpump run time in summer, shorter in winter)

template:
  - sensor:
  - name: "poolpump_stop"
    device_class: timestamp
    state: >
      {% set hrs = {'Spring': 6, 'Summer': 8, 'Autumn': 6, 'Winter': 4}.get(states('sensor.season'), 6) %}
      {{ today_at(states('input_datetime.poolpump_start')) + timedelta(hours=hrs) }}

The automation starts the pool pump at the specified time, but is does not stop the pump, no errors are displayed.

When I plug this into the template editor:

	{{ states('sensor.poolpump_stop') | as_datetime | as_local }}

I get an error

AttributeError: 'NoneType' object has no attribute 'tzinfo'

instead of getting the poolpump stop timecorrectly. So the automation starts the pump, but doesn’t stop it.

This used to work, but isn’t now. (i’m resurrecting this, I had some connection issues with the smart socket controlling the pool pump which have finally been resolved)

I tried recreating the template sensor, but there was no device class timestamp available in the gui, and the yaml version isn’t working as expected.

Some of the above is quite advanced, I didn’t write it, I got help from Taras, the original request and thread is marked as having a solution.

I simply set my pool pump on/off times tied to sunrise/sunset with offsets. So I use sunrise +2 hours and sunset -2 hours. This automatically will adjust the on/off times on an almost daily basis. I get about 6 hours of run time in the winter and about 9 hours of run time in the summer.

The indentation of the example you posted doesn’t match the indentation of the original example.

That error implies that sensor.poolpump_stop either doesn’t exist or its value is null (None). If its configuration is incorrect, it will fail to be created and so it won’t exist.