Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b2212e

Browse files
authored
Add example for python_script sensors
1 parent0f2023f commit1b2212e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

‎README.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Python source code are compiled and cached on load. You need to restart Home Ass
193193
sensor:
194194
- platform: python_script
195195
name: My IP address
196-
scan_interval: '00:05:00' # optional
196+
scan_interval: '00:05:00' # optional, default: 30s
197197
source: |
198198
import requests
199199
r = requests.get('https://api.ipify.org?format=json')
@@ -209,4 +209,18 @@ sensor:
209209
logger.debug("Update DB size")
210210
filename = self.hass.config.path('home-assistant_v2.db')
211211
self.state = round(os.stat(filename).st_size / 1_000_000, 1)
212-
```
212+
213+
- platform: python_script
214+
name: Instance external url #more info https://developers.home-assistant.io/docs/instance_url/
215+
scan_interval: '01:00:00' # optional
216+
source: |
217+
from homeassistant.helpers import network
218+
try:
219+
self.state = network.get_url(
220+
self.hass,
221+
allow_internal=False,
222+
)
223+
except network.NoURLAvailableError:
224+
raise MyInvalidValueError("Failed to find suitable URL for my integration")
225+
226+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp