Загрузка...

#63 'Set State' Service in Home Assistant | How to Add & Use

#setstate #setsensorstate #setsensorpythonscript #vccground #homeassistant
sensor state home assistant / home assistant sensor state / home assistant sensor template / home assistant sensor value template / home assistant set state / home assistant set state of entity / home assistant set state attributes / home assistant set state service / set state home assistant / set state python script / how to change a sensor value state

Intro:
*******
In this video, we will learn about how to integrate a Python script in Home Assistant to add a new service called "Set State" to force change the state of a sensor or an entity automatically from within an Automation or Script. This script is able to set any attribute like state, value, icon etc.
Scripts are placed in a python_scripts folder under the configuration directory. In my case it is /config/python_scripts/set_state.py. You then need to add the line python_script: in configuration.yaml and save it. Now to make it work, either restart Home Assistant or Reload PYTHON SCRIPTS under Yaml Configuration Reloading, in Developer Tools Section.

Manual Installation Hints:
Create config/python_scripts folder if you haven't already.
Copy set_state.py into the config/python_scripts folder.
Add python_script: to config/configuration.yaml if you haven't already.
Restart Home Assistant or Reload PYTHON SCRIPTS.

How to manually set state/value of sensor?
With this script in place, the example action could be:
action:
service: python_script.set_state
data_template:
entity_id: sensor.your_sensor_name
state: ON

Templates used in the video automation:
'{{ (states(''sensor.vindriktningbr_vindriktning_pm2_5'') != states(''sensor.dell_laptop_battery_level'')) }}'

'{{states(''sensor.vindriktningbr_vindriktning_pm2_5'')}}'

Here is an example of automations where the icon of sensor.garage_door is set based on changes in its state:

- alias: Garage Door Open
hide_entity: True
trigger:
platform: state
entity_id: sensor.garage_door
to: 'Open'
action:
- service: python_script.set_state
data_template:
entity_id: sensor.garage_door
icon: mdi:garage-open

- alias: Garage Door Closed
hide_entity: True
trigger:
platform: state
entity_id: sensor.garage_door
to: 'Closed'
action:
- service: python_script.set_state
data_template:
entity_id: sensor.garage_door
icon: mdi:garage

Important Links:
******************
Subscribe vccground: https://www.youtube.com/@the_vccground
Join vccground Telegram Discussion: https://t.me/vccground
Github: https://github.com/its-vccground

Download Python Script Folder: https://tinyurl.com/Set-State-Python-Script
Read about Python Scripts in Home Assistant: https://www.home-assistant.io/integrations/python_script
Documentation for Set State Service: https://github.com/xannor/hass_py_set_state#set-state
#30 Setting up RF Bridge & Python Scripts in Home Assistant: https://youtu.be/_9xZ-sfeb90

About us:
***********
Located in Delhi, India., We provide all kind of Customized Electronic and Smart Home Solutions. Do contact us for any Modification, Customization, Designing and Repairs of all Electronic and Smart Home Devices. WhatsApp your requirements to +91 9310248748 and we'll coordinate with you soon thereafter. For Business association: vccground3.3@gmail.com

Music Credits to:
*******************
Intro : Hope by Tobu. https://youtu.be/Y1Z3Q3O7IRE

Watch my other videos:
************************
#62 Fix your Tasmota Binary: https://youtu.be/GiN-MerlTsY?si=usds7fsfESOXjl62

#61 Max7219 LED Matrix Digital Clock & Scrolling Display in Tasmota & Home Assistant
https://youtu.be/CXXduaJ2tjg

#60 ATTiny13 DIY RF Door Window Sensor & Low battery Indicator | Ultra Low Power Long Battery Life: https://youtu.be/nHYqg-jIuag

#59 DIY 433MHz RF Door Sensor | Ultra Low Power Battery Operated | OPEN/CLOSE & Battery LOW/HI codes: https://youtu.be/Gs_2lIoOgK8

#58 Correcting the Single Code RF 433MHz Door Window Sensor | Sonoff DW1: https://youtu.be/8dT95zBeb1U

#57 Command Line Yaml Configuration Error Resolved: https://youtu.be/MKZ6B7tAXu0

#56 Wifi Router Watch Dog WDT 2.0: https://youtu.be/L9M8rRyUAcg

#55 The 5 minutes DIY Digital Clock: https://youtu.be/q_hUVOG8Mk4

#54 How to program Hex code to ATTiny: https://youtu.be/0Ecmg-tOt1k

#53 E77 Secret Revealed: https://youtu.be/gYs6Ua3pPoo

#52 How to program ATTiny Microcontrollers: https://youtu.be/4GOw7_hZi2w

#51 Sonoff Low or No Connectivity issue: https://youtu.be/H74POOYlqsU

#50 Games in Home Assistant: https://youtu.be/uxHKaw_ZaIU

#49 RF Door Sensor Awesome Modification: https://youtu.be/xVsBWU4PDhw

#48 Relay Modules Tips & Tricks: https://youtu.be/pEgNmpMHaR8

#47 Buzzer in Tasmota: https://youtu.be/7g80bi-VOhg

#46 PIR Motion Sensor in Tasmota: https://youtu.be/_OUg7yUehVc

#45 Member Counter in Home Assistant: https://youtu.be/J-4-8I2M4l0

Видео #63 'Set State' Service in Home Assistant | How to Add & Use канала vccground
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять