this is an app for Alexa i made:
###########################################################################################
# #
# Rene Tode ( [email protected] ) #
# ( with a lot off help from andrew cockburn (aimc) ) #
# 2016/3/18 Germany #
# #
###########################################################################################
import appdaemon.appapi as appapi
import datetime
import time
class alexa(appapi.AppDaemon):
def initialize(self):
self.sound = self.get_app("soundfunctions")
self.listen_state(self.alexa1,"input_boolean.alexa1")
self.listen_state(self.alexa2,"input_boolean.alexa2")
self.listen_state(self.alexa3,"input_boolean.alexa3")
self.listen_state(self.alexa4,"input_boolean.alexa4")
self.listen_state(self.alexa5,"input_boolean.alexa5")
self.listen_state(self.alexahkverwarming,"input_slider.woonkamerheizung")
self.listen_state(self.alexakkverwarming,"input_slider.keukenheizung")
def alexa1(self, entity, attribute, old, new, kwargs):
if new != "on":
speaktext = "Alexa heeft alle verlichting uitgedaan"
self.turn_off("input_boolean.allesuit")
self.turn_on("input_boolean.alexa1")
self.sound.say(speaktext,"nl","1")
def alexa2(self, entity, attribute, old, new, kwargs):
if new == "on":
speaktext = "Alexa heeft de woonkamer verlichting aangedaan"
self.turn_on("switch.hbank")
self.turn_on("switch.hboog")
self.turn_on("switch.hrozenhoek")
self.turn_on("switch.hkachel")
else:
speaktext = "Alexa heeft de woonkamer verlichting uitgedaan"
self.turn_off("switch.hbank")
self.turn_off("switch.hboog")
self.turn_off("switch.hrozenhoek")
self.turn_off("switch.hkachel")
self.sound.say(speaktext,"nl","1")
def alexa3(self, entity, attribute, old, new, kwargs):
if new == "on":
speaktext = "Alexa heeft de eetkamer verlichting aangedaan"
self.turn_on("switch.epchoek")
self.turn_on("switch.eraamhoek")
self.turn_on("switch.ewandmeubel")
else:
speaktext = "Alexa heeft de eetkamer verlichting uitgedaan"
self.turn_off("switch.epchoek")
self.turn_off("switch.eraamhoek")
self.turn_off("switch.ewandmeubel")
self.sound.say(speaktext,"nl","1")
def alexa4(self, entity, attribute, old, new, kwargs):
if new == "on":
speaktext = "Alexa heeft de verlichting in de gang aangedaan"
self.turn_on("light.vitrine_in_de_gang")
else:
speaktext = "Alexa heeft de verlichting in de gang uitgedaan"
self.turn_off("light.vitrine_in_de_gang")
self.sound.say(speaktext,"nl","1")
def alexa5(self, entity, attribute, old, new, kwargs):
if new == "on":
temper = str(self.get_state("sensor.huiskamer_box_4_1"))
speaktext = "De temperatuur in de woonkamer is nu " + temper + " graden"
self.turn_off("input_boolean.alexa5")
self.sound.say(speaktext,"nl","1")
def alexahkverwarming(self, entity, attribute, old, new, kwargs):
self.call_service("input_slider/select_value", entity_id="input_slider.huiskamerthermostaata",value=float(new))
self.call_service("input_slider/select_value", entity_id="input_slider.huiskamerthermostaatb",value=float(new)-1)
speaktext = "Alexa heeft de thermostaat van de woonkamer op " + new + " graden gesteld"
self.sound.say(speaktext,"nl","1")
def alexakkverwarming(self, entity, attribute, old, new, kwargs):
self.call_service("input_slider/select_value", entity_id="input_slider.keukenthermostaata",value=float(new))
self.call_service("input_slider/select_value", entity_id="input_slider.keukenthermostaatb",value=float(new)-1)
speaktext = "Alexa heeft de thermostaat van de keuken op " + new + " graden gesteld"
self.sound.say(speaktext,"nl","1")
in my customize.yaml i have this:
input_slider.keukenheizung:
emulated_hue: true
emulated_hue_name: "heizung kueche"
input_slider.woonkamerheizung:
emulated_hue: true
emulated_hue_name: "heizung wohnzimmer"
input_boolean.alexa1:
emulated_hue: true
emulated_hue_name: "alle beleuchtung"
input_boolean.alexa2:
emulated_hue: true
emulated_hue_name: "lampe wohnzimmer"
input_boolean.alexa3:
emulated_hue: true
emulated_hue_name: "lampe esszimmer"
input_boolean.alexa4:
emulated_hue: true
emulated_hue_name: "lampe flur"
input_boolean.alexa5:
emulated_hue: true
emulated_hue_name: "temperatur"
as you see i have created some input_booleans before that.
forget about the input slider, it is possible but you have to change the emulated hue code for that.
where i use self.sound.say you could use a notify or a service call to a TTS in HA
there is a lot of dutch and german in there, but the dutch is spoken text and the german what i say to Alexa
hope this helps.