How to manually set state/value of sensor?

i have a sensor [

SONOFF SNZB-03 ZigBee Motion Sensor

](SNZB-03 - SONOFF Official)

the cool down of the sensor is to long so i want to use this code, for example the sensor detect motion and after 5 seconds it will reset to no motion.

Create a trigger-based template binary sensor with a state trigger looking for your motion sensor going on and an auto_off of 5 seconds.

Changing that doesnā€™t mean the sensor will produce more motion events. In all likeliness, youā€™ll have the same number of motion events but your sensor now turns off after 5 seconds. You should adjust the settings in the hardware, not use a ill-though-out band aide.

Hi,

I have red a lot of posts, but probably not the right oneā€¦

I want to use a value from a sensor to be written via set_state.py to the other entity, like:
in the automation i wrote:
state: {{ states(ā€˜sensor.power_pv_totalā€™)}}
entity_id: sensor.ccu3_webui_sv_current_plant_power

But I am struggeling with the syntax to do it right.
Can someone help out here.

Regards

Gerhard

Why do you want to go this (wrong) way, rather than just setting up a template sensor?

template:
  - sensor:
      - name: "Copy of other sensor"
        state: "{{ states('sensor.power_pv_total') }}"

What are you actually really trying to do? See sections 8 and 11 of this guide:

Got it, thanks.

Thanks, works like a charm!

service: python_script.set_state
data:
  entity_id: sensor.ccu3_webui_sv_current_plant_power
  state: "{{ states('sensor.power_pv_total') }}"

and/or to change attribute(s):

data:
  entity_id: sensor.ccu3_webui_sv_current_plant_power
  state: "{{ states('sensor.power_pv_total') }}"  # optional if attribute(s) are listed
  name_of_attribute: "some_value"
  brightness: "{{ state_attr('switch.adaptive_lighting_bathroom_light','brightness_pct') }}"
  current_tilt_position: "{{ state_attr(trigger.entity_id, 'current_position') }}"
  nighmode: "on"
  message: "Some string message"
  image: "/path/image_name"
  timer: etc...
  

Note though that the state|attributes written by the script does not survive a system restart nor does it survive any state updates which occur through the integration which created sensor.ccu3_webui_sv_current_plant_power.

1 Like

This works perfectly thank you! My android TV only has a state of off or on. This script allows me to set a status of playing or paused, to better control the TV!

Hi,

Thanks so much for this, It took me a ages to finally work out my problem.

Basically I have a Switchbot Bot in toggle mode. So when I turn it on the bot then presses the button and then turns back, and this is not reflected in Home Assistant.

So with this I was able to create an automation that would reset the bot switch back to ā€œoffā€ so when the user looks at it the status in Home assistant or as I have it exported to homekit, HomeKit.

alias: Office - Revert bot state to OFF
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.switchbot_bot
    to: "on"
condition: []
action:
  - service: python_script.set_state
    data:
      entity_id: switch.switchbot_bot
      state: "off"
mode: single

When I initially tried this, I just called the swithc service and that would cause the bot to press twice when it reset the switch to the proper mod, with this I just get a single press.

Thanks again.