Polling a sensor at a fixed interval — say, every 5 minutes — is simple to set up. But in practice, it can be wasteful or inadequate: polling too often wastes bandwidth and may hit rate limits, while polling too slowly can leave your data stale when you need it most.

Ideally, we’d poll frequently when someone might be watching, and rarely (or not at all) when the house is asleep or empty. That means dynamic polling based on context.

This post shows how I built such a dynamic polling strategy for the Danish public transport integration, HAFAS, in Home Assistant. But the idea applies to any sensor with on-demand updates.

Note: Home Assistant does have a Rejseplanen integration directly, but its defunct as Rejseplanen deprecated their v1 API. The HAFAS integration is alive and well.


Why Control Polling at All?

Most Home Assistant integrations poll their data on a regular basis. The Rejseplanen integration is no exception — it polls automatically unless you override it.

But instead of setting a global scan_interval, which would affect every entity in the integration, we can disable polling at the entity level via the UI and trigger updates ourselves.

Here’s how to do that: 👉 Why use an automation instead of changing the integration’s polling configuration?


Building a Custom Update Schedule

This post presents one strategy. My choices reflect a typical workday:

  • Frequent updates during morning and afternoon commutes
  • Less frequent updates during the day
  • Sparse updates in the evening or at night

But you can adapt it to your routine: some may want more polling on weekends, or more updates in the evening.

To detect weekdays and holidays, I use Home Assistant’s Workday Sensor, which returns on during normal workdays and off on weekends or holidays. It’s great for this kind of logic.


The Automation: Smart Polling

Make sure to disable automatic polling first (as described above). Then replace sensor.rejseplanen and binary_sensor.workday with your actual entity ID.

# Example automation: Smart polling for train departures
automation:
  - alias: timer/rejseplanen (smart schedule)
    description: Update train departures with smart frequency based on time and day.
    mode: single
    trigger:
      - platform: time_pattern
        minutes: "/1"
    condition: []
    action:
      - choose:
          - alias: "[frequent] Weekday Morning Commute (06:30–08:30)"
            conditions:
              - condition: time
                after: "06:30:00"
                before: "08:30:00"
              - condition: state
                entity_id: binary_sensor.workday
                state: "on"
              - condition: template
                value_template: "{{ now().minute % 2 == 0 }}"
            sequence:
              - service: homeassistant.update_entity
                data:
                  entity_id: sensor.rejseplanen

          - alias: "[off-peak] Weekday Midday (08:30–14:00)"
            conditions:
              - condition: time
                after: "08:30:00"
                before: "14:00:00"
              - condition: state
                entity_id: binary_sensor.workday
                state: "on"
              - condition: template
                value_template: "{{ now().minute % 8 == 0 }}"
            sequence:
              - service: homeassistant.update_entity
                data:
                  entity_id: sensor.rejseplanen

          - alias: "[frequent] Weekday Afternoon Return (14:00–19:00)"
            conditions:
              - condition: time
                after: "14:00:00"
                before: "19:00:00"
              - condition: state
                entity_id: binary_sensor.workday
                state: "on"
              - condition: template
                value_template: "{{ now().minute % 2 == 0 }}"
            sequence:
              - service: homeassistant.update_entity
                data:
                  entity_id: sensor.rejseplanen

          - alias: "[infrequent] Weekday Evening (19:00–22:00)"
            conditions:
              - condition: time
                after: "19:00:00"
                before: "22:00:00"
              - condition: state
                entity_id: binary_sensor.workday
                state: "on"
              - condition: template
                value_template: "{{ now().minute % 15 == 0 }}"
            sequence:
              - service: homeassistant.update_entity
                data:
                  entity_id: sensor.rejseplanen

          - alias: "[off-peak] Weekend Daytime (08:00–22:00)"
            conditions:
              - condition: time
                after: "08:00:00"
                before: "22:00:00"
              - condition: state
                entity_id: binary_sensor.workday
                state: "off"
              - condition: template
                value_template: "{{ now().minute % 8 == 0 }}"
            sequence:
              - service: homeassistant.update_entity
                data:
                  entity_id: sensor.rejseplanen

          - alias: "[infrequent] All Nights (22:00–06:30)"
            conditions:
              - condition: or
                conditions:
                  - condition: time
                    after: "22:00:00"
                  - condition: time
                    before: "06:30:00"
              - condition: template
                value_template: "{{ now().minute % 15 == 0 }}"
            sequence:
              - service: homeassistant.update_entity
                data:
                  entity_id: sensor.rejseplanen

Ideas for Further Improvement

You can make this even smarter by reacting to presence:

  • Is anyone home?
  • Has someone opened the front door?
  • Is there motion in the hallway — near a dashboard or wall tablet?

These conditions can be placed at the top of the choose: block so they take priority. That way, updates happen right when someone might be looking, regardless of the time.


Conclusion

With this setup, your dashboards and displays will stay fresh when people care, and quiet down when they don’t.

Perfect for hallway tablets, entryway info panels, or just for keeping the Rejseplanen API happy while saving bandwidth.

Want even more control? Extend the logic with presence detection, calendar events, or anything else you can automate in Home Assistant.