mirror of
https://github.com/skalavala/mysmarthome.git
synced 2025-08-20 20:17:12 +00:00
Back Alive!
This commit is contained in:
53
python_scripts/batteries.py
Executable file
53
python_scripts/batteries.py
Executable file
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Author : Suresh Kalavala
|
||||
Date : 02/09/2017
|
||||
Description : Returns the appripriate icon for the entity
|
||||
File : batteries.py - python_script for batteries
|
||||
"""
|
||||
def get_icon(bat_level):
|
||||
icon = "mdi-unknown"
|
||||
battery_round = round(int(bat_level)/10)*10
|
||||
if battery_round >= 100:
|
||||
icon = "mdi:battery"
|
||||
elif battery_round > 0:
|
||||
icon = "mdi:battery-{}".format(str(battery_round))
|
||||
else:
|
||||
icon = "mdi:battery-alert"
|
||||
return icon
|
||||
|
||||
try:
|
||||
attribs = {}
|
||||
entity_id = data.get('entity_id')
|
||||
battery_value = data.get('battery_value', 0)
|
||||
|
||||
attribs["icon"] = get_icon(battery_value)
|
||||
attribs["unit_of_measurement"] = "%"
|
||||
attribs["friendly_name"] = entity_id.split('.')[1].replace("_", " ").title() + "'s Battery"
|
||||
|
||||
hass.states.set(entity_id, battery_value, attributes=attribs)
|
||||
except Exception as ex:
|
||||
logger.error(str(ex))
|
||||
|
||||
"""
|
||||
- alias: Update ZWave Battery Levels
|
||||
initial_state: true
|
||||
trigger:
|
||||
- platform: event
|
||||
event_type: state_changed
|
||||
condition:
|
||||
- condition: template
|
||||
value_template: "{{ trigger.event.data.entity_id is not none }}"
|
||||
- condition: template
|
||||
value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'zwave' }}"
|
||||
- condition: template
|
||||
value_template: "{{ trigger.event.data.new_state.attributes is not none }}"
|
||||
- condition: template
|
||||
value_template: "{{ trigger.event.data.new_state.attributes.battery_level | trim != '' }}"
|
||||
- condition: template
|
||||
value_template: "{{ trigger.event.data.new_state.attributes.battery_level | default(999) | int != 999 }}"
|
||||
action:
|
||||
- service: python_script.batteries
|
||||
data_template:
|
||||
entity_id: "input_label.{{- trigger.event.data.entity_id.split('.')[1] -}}"
|
||||
battery_value: '{{ trigger.event.data.new_state.attributes.battery_level }}'
|
||||
"""
|
3
python_scripts/hello_world.py
Executable file
3
python_scripts/hello_world.py
Executable file
@@ -0,0 +1,3 @@
|
||||
name = data.get('name', 'world')
|
||||
logger.info("Hello {}".format(name))
|
||||
hass.bus.fire(name, { "wow": "from a Python script!" })
|
17
python_scripts/hide_unwanted.py
Executable file
17
python_scripts/hide_unwanted.py
Executable file
@@ -0,0 +1,17 @@
|
||||
'''
|
||||
@Author : Mahasri Kalavala
|
||||
@Date : 08/27/2017
|
||||
@Description : This python script hides all the sensors that are Online, so that
|
||||
ONLY the Offline sensors are visible in the UI
|
||||
'''
|
||||
for entity_id in hass.states.entity_ids('sensor'):
|
||||
entity_state_object = hass.states.get(entity_id)
|
||||
attributes = entity_state_object.attributes.copy()
|
||||
|
||||
""" Hide all the entities that have 'Online' Status """
|
||||
if entity_state_object.state == 'Online':
|
||||
attributes['hidden'] = True
|
||||
else:
|
||||
attributes['hidden'] = False
|
||||
|
||||
hass.states.set(entity_id, entity_state_object.state, attributes=attributes)
|
10
python_scripts/peopleathome.py
Executable file
10
python_scripts/peopleathome.py
Executable file
@@ -0,0 +1,10 @@
|
||||
home = 0
|
||||
for entity_id in hass.states.entity_ids('device_tracker'):
|
||||
state = hass.states.get(entity_id)
|
||||
if state.state == 'home':
|
||||
home = home + 1
|
||||
|
||||
hass.states.set('sensor.people_home', home, {
|
||||
'unit_of_measurement': 'people',
|
||||
'friendly_name': 'People home'
|
||||
})
|
9
python_scripts/rgbcolor.py
Executable file
9
python_scripts/rgbcolor.py
Executable file
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
{"entity_id":"light.hue_color_lamp_2", "rgb_color": [254, 0, 0] }
|
||||
"""
|
||||
|
||||
entity_id = data.get('entity_id')
|
||||
rgb_color = data.get('rgb_color', [255, 255, 255])
|
||||
if entity_id is not None:
|
||||
service_data = {"entity_id": entity_id, "rgb_color": rgb_color, "brightness": 255 }
|
||||
hass.services.call("light", "turn_on", service_data, False)
|
Reference in New Issue
Block a user