improved scene detect

This commit is contained in:
John Lancaster
2024-06-11 23:03:59 -05:00
parent 5b56c29999
commit bc175f75d9
6 changed files with 74 additions and 48 deletions

49
apps/hello_world/hello.py Normal file
View File

@@ -0,0 +1,49 @@
import asyncio
import json
from appdaemon.adapi import ADAPI
from appdaemon.plugins.hass.hassapi import Hass
class HelloWorld(Hass):
def initialize(self):
self.log('Hello World')
# self.listen_state(
# callback=self.temp_callback,
# entity_id='sensor.temperature_nest',
# attribute='state',
# threshold=65.0,
# )
# self.listen_state(
# callback=self.temp_callback,
# entity_id='light.living_room',
# attribute='state',
# threshold=65.0,
# )
async def temp_callback(self, entity, attribute, old, new, kwargs):
self.log('Temp callback')
temp = await self.get_state('sensor.temperature_nest')
# self.log(json.dumps(temp, indent=4))
self.AD.loop.create_task(self.unreliable_call())
if float(temp) <= kwargs['threshold']:
self.log(f'{entity} is below the threshold')
self.AD.loop.create_task(self.unreliable_call())
self.log('Doing some other, more reliable stuff')
await asyncio.sleep(2.0)
self.log(f'{entity} done')
async def unreliable_call(self):
self.log('Calling unreliable cloud service....')
await asyncio.sleep(5.0)
# await self.call_service('climate/set_temperature', entity_id='climate.living_room', temperature=70)
self.log('Cloud service returned')
def entities_ending_with(self, ending_str: str):
entities = [
entity_id
for entity_id, state in self.get_state().items()
if entity_id.endswith(ending_str)
]
return entities

View File

@@ -0,0 +1,3 @@
HelloWorld:
module: hello
class: HelloWorld