diff --git a/configuration/automations/hallway.yaml b/configuration/automations/hallway.yaml index 5b67c1b..14de4bc 100644 --- a/configuration/automations/hallway.yaml +++ b/configuration/automations/hallway.yaml @@ -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 alias: '[Hallway] Button single press' mode: single @@ -41,6 +56,7 @@ entity_id: binary_sensor.hallway_motion_sensor from: 'on' to: 'off' + for: 00:00:05 action: - service: script.hallway_lights_off diff --git a/configuration/configuration.yaml b/configuration/configuration.yaml index 140a519..d4fdec4 100644 --- a/configuration/configuration.yaml +++ b/configuration/configuration.yaml @@ -78,6 +78,7 @@ media_source: mobile_app: my: person: +python_script: recorder: db_url: !secret postgres_url scene: !include scenes.yaml diff --git a/home-assistant.yml b/home-assistant.yml index e1b6027..a12c18d 100644 --- a/home-assistant.yml +++ b/home-assistant.yml @@ -45,3 +45,8 @@ copy: src: configuration/secrets.yaml dest: '{{ pwd_config }}/secrets.yaml' + - name: Copy scripts + copy: + src: python_scripts + dest: '{{ pwd_config }}' + directory_mode: yes \ No newline at end of file diff --git a/python_scripts/set_state.py b/python_scripts/set_state.py new file mode 100755 index 0000000..fecbd9a --- /dev/null +++ b/python_scripts/set_state.py @@ -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)