1
0

Use Aquara motion super sensor

This commit is contained in:
Przemek Grondek 2021-12-06 23:31:28 +01:00
parent 2abaa24288
commit a21f418f74
4 changed files with 62 additions and 0 deletions

View File

@ -1,3 +1,18 @@
- id: hallway-motion-reset
alias: '[Hallway] Super sensor reset'
mode: restart
trigger:
- entity_id: binary_sensor.hallway_motion_sensor
for: 00:00:05
from: 'off'
platform: state
to: 'on'
action:
- data_template:
entity_id: binary_sensor.hallway_motion_sensor
state: 'off'
service: python_script.set_state
- id: hallway-button - id: hallway-button
alias: '[Hallway] Button single press' alias: '[Hallway] Button single press'
mode: single mode: single
@ -41,6 +56,7 @@
entity_id: binary_sensor.hallway_motion_sensor entity_id: binary_sensor.hallway_motion_sensor
from: 'on' from: 'on'
to: 'off' to: 'off'
for: 00:00:05
action: action:
- service: script.hallway_lights_off - service: script.hallway_lights_off

View File

@ -78,6 +78,7 @@ media_source:
mobile_app: mobile_app:
my: my:
person: person:
python_script:
recorder: recorder:
db_url: !secret postgres_url db_url: !secret postgres_url
scene: !include scenes.yaml scene: !include scenes.yaml

View File

@ -45,3 +45,8 @@
copy: copy:
src: configuration/secrets.yaml src: configuration/secrets.yaml
dest: '{{ pwd_config }}/secrets.yaml' dest: '{{ pwd_config }}/secrets.yaml'
- name: Copy scripts
copy:
src: python_scripts
dest: '{{ pwd_config }}'
directory_mode: yes

40
python_scripts/set_state.py Executable file
View File

@ -0,0 +1,40 @@
"""Set the state or other attributes for the specified entity."""
# ========================================================================================
# python_scripts/set_state.py
# modified from -
# https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/37
# ========================================================================================
# ----------------------------------------------------------------------------------------
# Set the state or other attributes for the specified entity.
# Updates from @xannor so that a new entity can be created if it does not exist.
# ----------------------------------------------------------------------------------------
inputEntity = data.get("entity_id")
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
else:
inputStateObject = hass.states.get(inputEntity)
if inputStateObject is None and not data.get("allow_create"):
logger.warning("===== unknown entity_id: %s", inputEntity)
else:
if not inputStateObject is None:
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
else:
inputAttributesObject = {}
for item in data:
newAttribute = data.get(item)
logger.debug("===== item = {0}; value = {1}".format(item, newAttribute))
if item == "entity_id":
continue # already handled
elif item == "allow_create":
continue # already handled
elif item == "state":
inputState = newAttribute
else:
inputAttributesObject[item] = newAttribute
hass.states.set(inputEntity, inputState, inputAttributesObject)