@@ -147,11 +147,12 @@ async def _get_media_url(hass, local_path: str) -> str:
147147 return f"{ base_url } { local_path } "
148148
149149
150- def _get_volume (options , base_vol_key , base_default ):
151- """Geef het juiste volume terug op basis van dag/nacht instelling ."""
150+ def _get_volume (options , base_vol_key , base_default , hass = None ):
151+ """Geef het juiste volume terug op basis van dag/nacht en open ramen/deuren ."""
152152 raw = options .get (base_vol_key , base_default )
153153 volume = raw / 100 if raw > 1 else raw
154154
155+ # Nacht volume
155156 night_enabled = options .get ("night_volume_enabled" , False )
156157 if night_enabled :
157158 night_start = int (options .get ("night_start_hour" , 22 ))
@@ -160,6 +161,17 @@ def _get_volume(options, base_vol_key, base_default):
160161 raw_night = options .get ("night_volume" , 10 )
161162 volume = raw_night / 100 if raw_night > 1 else raw_night
162163
164+ # Open ramen/deuren volume
165+ open_sensor_enabled = options .get ("open_sensor_enabled" , False )
166+ if open_sensor_enabled and hass is not None :
167+ sensor = options .get ("open_sensor_entity" , "" )
168+ if sensor :
169+ state = hass .states .get (sensor )
170+ if state and state .state == "on" :
171+ raw_open = options .get ("open_sensor_volume" , 5 )
172+ volume = raw_open / 100 if raw_open > 1 else raw_open
173+ _LOGGER .debug (f"Open sensor active, using reduced volume: { volume } " )
174+
163175 return volume
164176
165177
@@ -170,17 +182,17 @@ async def play_adhan(hass: HomeAssistant, entry: ConfigEntry, prayer_type: str):
170182 if prayer_type == "fajr" :
171183 speaker = options .get (CONF_FAJR_SPEAKER , ["media_player.adhan_speakers" ])
172184 if isinstance (speaker , str ): speaker = [speaker ]
173- volume = _get_volume (options , CONF_FAJR_VOLUME , 10 )
185+ volume = _get_volume (options , CONF_FAJR_VOLUME , 10 , hass )
174186 sound = options .get (CONF_FAJR_SOUND , "01-adhan-fajr.mp3" )
175187 elif prayer_type == "jumat" :
176188 speaker = options .get ("jumat_speaker" , options .get (CONF_DAY_SPEAKER , ["media_player.adhan_speakers" ]))
177189 if isinstance (speaker , str ): speaker = [speaker ]
178- volume = _get_volume (options , "jumat_volume" , options .get (CONF_DAY_VOLUME , 50 ))
190+ volume = _get_volume (options , "jumat_volume" , options .get (CONF_DAY_VOLUME , 50 ), hass )
179191 sound = options .get ("jumat_sound" , options .get (CONF_DAY_SOUND , "01-adhan.mp3" ))
180192 else :
181193 speaker = options .get (CONF_DAY_SPEAKER , ["media_player.adhan_speakers" ])
182194 if isinstance (speaker , str ): speaker = [speaker ]
183- volume = _get_volume (options , CONF_DAY_VOLUME , 50 )
195+ volume = _get_volume (options , CONF_DAY_VOLUME , 50 , hass )
184196 sound = options .get (CONF_DAY_SOUND , "01-adhan.mp3" )
185197
186198 play_method = options .get (CONF_PLAY_METHOD , "media_player" )
@@ -246,7 +258,7 @@ async def check_reminders(hass, entry, coordinator, now_ts, prayers):
246258 lang = options .get (f"reminder_{ r_num } _lang" , "nl" )
247259 speaker = options .get (CONF_DAY_SPEAKER , ["media_player.adhan_speakers" ])
248260 if isinstance (speaker , str ): speaker = [speaker ]
249- volume = _get_volume (options , CONF_DAY_VOLUME , 50 )
261+ volume = _get_volume (options , CONF_DAY_VOLUME , 50 , hass )
250262
251263 for prayer_name , time_str in prayers .items ():
252264 today = datetime .now ().strftime ("%Y-%m-%d" )
@@ -320,7 +332,7 @@ async def check_tarhim(hass: HomeAssistant, entry: ConfigEntry, coordinator, now
320332 if abs (now_ts - tarhim_ts ) < 30 :
321333 speaker = options .get (CONF_TARHIM_SPEAKER , ["media_player.adhan_speakers" ])
322334 if isinstance (speaker , str ): speaker = [speaker ]
323- volume = _get_volume (options , CONF_TARHIM_VOLUME , 10 )
335+ volume = _get_volume (options , CONF_TARHIM_VOLUME , 10 , hass )
324336 sound = options .get (CONF_TARHIM_SOUND , "01-tarhim.mp3" )
325337 media_path = await _get_media_url (hass , f"/local/nida/sounds/{ sound } " )
326338
@@ -409,7 +421,7 @@ async def handle_test_reminder(call):
409421 text = text .replace ("[minutes]" , str (int (minutes ))).replace ("[prayer]" , prayer )
410422 speaker = options .get (CONF_DAY_SPEAKER , ["media_player.adhan_speakers" ])
411423 if isinstance (speaker , str ): speaker = [speaker ]
412- volume = _get_volume (options , CONF_DAY_VOLUME , 50 )
424+ volume = _get_volume (options , CONF_DAY_VOLUME , 50 , hass )
413425
414426 if sound :
415427 media_path = await _get_media_url (hass , f"/local/nida/sounds/{ sound } " )
0 commit comments