diff --git a/homeassistant/components/gtfs/sensor.py b/homeassistant/components/gtfs/sensor.py index 77e1d0f7d33..9fac4d01926 100644 --- a/homeassistant/components/gtfs/sensor.py +++ b/homeassistant/components/gtfs/sensor.py @@ -610,14 +610,6 @@ class GTFSDepartureSensor(SensorEntity): self._include_tomorrow, ) - # Define the state as a UTC timestamp with ISO 8601 format - if not self._departure: - self._state = None - else: - self._state = self._departure["departure_time"].replace( - tzinfo=dt_util.UTC - ) - # Fetch trip and route details once, unless updated if not self._departure: self._trip = None @@ -648,6 +640,19 @@ class GTFSDepartureSensor(SensorEntity): ) self._agency = False + # Define the state as a UTC timestamp with ISO 8601 format + if not self._departure: + self._state = None + else: + if self._agency: + self._state = self._departure["departure_time"].replace( + tzinfo=dt_util.get_time_zone(self._agency.agency_timezone) + ) + else: + self._state = self._departure["departure_time"].replace( + tzinfo=dt_util.UTC + ) + # Assign attributes, icon and name self.update_attributes()