2024年11月24日星期日 下午2:40:43

Making Aqara Motion Sensor is detected every two minutes change to 5 seconds.(Making Xiaomi Motion Sensor a Super Motion Sensor)

2 年 前
#17642 引用
Making Xiaomi Motion Sensor a Super Motion Sensor -Making Xiaomi Motion Sensor is detected every two minutes change  to 5 seconds.

Usually Xiaomi motion sensor is detected every two minutes. But with a little work, you can change that time to 5 seconds.

A year ago I made my Xiaomi motion sensors to Super motion sensors. Even after a year, Xiaomi motion sensors are working very well.

This method is applicable to both Xiaomi original motion sensor and Aqara version motion sensor.

How to make Xiaomi motion sensor to Super motion sensor.

https://community.smartthings.com/t/making-xiaomi-motion-sensor-a-super-motion-sensor/139806

http://livebywant.tistory.com/13?category=703455
0
2 年 前
#17697 引用

This hardware motion sensor hack

https://livebywant.tistory.com/13?category=703455

This hardware motion sensor hack allows motion to be detected every 5 seconds, however it still takes 300 seconds to reset the state to off.


AppDaemon app

An AppDaemon app to reset Xiaomi Aqara motion sensors after a given timeout

https://github.com/wernerhp/ha.appdaemon.aqara_motion_sensors



Set State script

https://github.com/rodpayne/home-assistant/blob/main/.homeassistant/python_scripts/set_state.py

Here is an updated script that has been generalized to be able to set any attribute.
https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/9?u=msly

#==================================================================================================
#  python_scripts/set_state.py
#==================================================================================================

#--------------------------------------------------------------------------------------------------
# Set the state or other attributes for the entity specified in the Automation Action
#--------------------------------------------------------------------------------------------------

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)
    inputState = inputStateObject.state
    inputAttributesObject = inputStateObject.attributes.copy()

    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 == 'state':
            inputState = newAttribute
        else:
            inputAttributesObject[item] = newAttribute
        
    hass.states.set(inputEntity, inputState, inputAttributesObject)




0
1 年 前
#20448 引用
You can do that using the REST API with curl - https://home-assistant.io/developers/rest_api/#post-apistatesltentity_id

https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/2?u=msly
0
1 年 前
#20449 引用


Instructions on how to setup Python scripts within Home Assistant
https://www.home-assistant.io/integrations/python_script

step 1.Create the folder <config>/python_scripts

/home/homeassistant20221103/python_scripts


step 2.Create a file <config>/python_scripts/hello_world.py in the folder and give it this content:
/home/homeassistant20221103/python_scripts/set_state.py


#==================================================================================================
#  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 entity specified in the Automation Action
#--------------------------------------------------------------------------------------------------

# ----------------------------------------------------------------------------------------
# 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)



step 3.Add to configuration.yaml:
python_script:


#https://github.com/hasscc/hass-edge-tts
tts:
  - platform: edge_tts
    language: zh-CN # Default language or voice (Optional)
#https://www.home-assistant.io/integrations/python_script/
python_script:

input_boolean:
  input_boolean_wife:

step4 .docker restart ha


0
1 年 前
#20450 引用
step 5.

http://192.168.2.50:38123/developer-tools/state

Set the current state representation of an entity within Home Assistant.
If the entity belongs to a device, there will be no actual communication with that device.

entity:
binary_sensor.motion_sensor_4


Tip!
Press 'e' on any page to open the entity search dialog

state

off


or

Clear


or

Cleared


State attributes (YAML, optional)

device_class: motion
friendly_name: Aqara Motion Sensor




0
1 年 前
#20451 引用
step 6.

automation

https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/22?u=msly

 service: python_script.set_state
  data_template:
    entity_id: switch.shelly1_basement
    state: "on"
0