本帖最后由 czweb 于 2018-4-14 10:58 编辑
如何才能把ping里的host的ip取出来,显示在名称下面?
我现在是用了笨办法,用extra_data_template属性直接接写在上面的,而不是读出来的。哪位大神指点指点有办法读取吗?
####用来检测有ip的设备状态
binary_sensor:
- platform: ping
name: route_internet
host: 192.168.2.1
scan_interval: 10
cout: 2
- platform: ping
name: radar4
host: 192.168.2.4
scan_interval: 10
cout: 2
- platform: ping
name: radar5
host: 192.168.2.5
scan_interval: 10
cout: 2
- platform: ping
name: radar6
host: 192.168.2.6
scan_interval: 10
cout: 2
- platform: ping
name: radar7
host: 192.168.2.7
scan_interval: 10
cout: 2
- platform: ping
name: radar8
host: 192.168.2.8
scan_interval: 10
cout: 2
- platform: ping
name: camera_dvr
host: 192.168.2.203
scan_interval: 10
cout: 2
- platform: ping
name: route_ap1
host: 192.168.2.251
scan_interval: 10
cout: 2
- platform: ping
name: route_ap2
host: 192.168.2.252
scan_interval: 10
cout: 2
- platform: ping
name: route_ap3
host: 192.168.2.253
scan_interval: 10
cout: 2
group:
group_binary_sensor:
control: hidden
name: 在线监测组
view: no
icon: mdi:radar
entities:
- binary_sensor.radar4
- binary_sensor.radar5
- binary_sensor.radar6
- binary_sensor.radar7
- binary_sensor.radar8
- binary_sensor.camera_dvr
- binary_sensor.route_internet
- binary_sensor.route_ap1
- binary_sensor.route_ap2
- binary_sensor.route_ap3
homeassistant:
customize:
binary_sensor.radar4:
friendly_name: 雷达-宇宙有多大
icon: mdi:radar
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.4"}
binary_sensor.radar5:
friendly_name: 雷达-地球24小时
icon: mdi:radar
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.5"}
binary_sensor.radar6:
friendly_name: 雷达-未来100亿年
icon: mdi:radar
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.6"}
binary_sensor.radar7:
friendly_name: 雷达-裸眼3D火箭雷达
icon: mdi:radar
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.7"}
binary_sensor.radar8:
friendly_name: 雷达-太空绘画墙
icon: mdi:radar
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.8"}
binary_sensor.camera_dvr:
friendly_name: 监控录像机
icon: mdi:cctv
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.203"}
binary_sensor.route_internet:
friendly_name: 路由器-外网网关
icon: mdi:router-wireless
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.1"}
binary_sensor.route_ap1:
friendly_name: 路由器-无线AP1
icon: mdi:router-wireless
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.251"}
binary_sensor.route_ap2:
friendly_name: 路由器-无线AP2
icon: mdi:router-wireless
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.252"}
binary_sensor.route_ap3:
friendly_name: 路由器-无线AP3
icon: mdi:router-wireless
templates:
_stateDisplay: "if (state === 'on') return '在线'; else return state;"
rgb_color: "if (state === 'on') return [255, 190, 0]; else return [100, 100, 135];"
extra_data_template:
- ${"IP:192.168.2.253"}
|