Alexa Audit

I have created an Appdeamon script which will allow Alexa to announce the following states:-

Inside temperature
Outside temperature
selected lights
selected switches
selected battery levels

This script requires that the Alexa notify script is working see

This script simply collects the above information into a single message. This message is then triggered by a boolean switch. This could by a call to Alexa say “Alexa turn on Living Room Audit”.

Documentation for the parameters required are in the script.

#
# Audit feature to get Alexa to announce HA states for :
#
#    Inside Temperature 
#    Outside Temperature 
#    Lights
#    Switches
#    Batteries
#
# Program requires the following parameters
#
#    Title: Name Alexa announces eg Living room Audit
#    Trigger: Switch to trigger program 
#    Notify: Name of Alexa Notify service
#    Temp-Inside: Name of sensor
#    Temp-Outside: Name of sensor
#    Light: list of lights
#    Switch: List of switches
#    battery: list of sensors with battery levels
#
# Title,Trigger and Notify parameters are mandatory, other parameters that not required must be set to none    
#
# Example config 
#
# AuditAlexa:
# module: AuditAlexa
# class: Auditalexa
# title: "Living Room Audit"
# trigger: "input_boolean.audit_light"
# notify: "alexalr"
# temp-inside: "sensor.temperature_158d0001b9205b"
# temp-outside: "sensor.dark_sky_temperature"
# light:
#   - light.living_room_lights
#   - light.dining_room_lights
#   - light.gateway_light_34ce0081452d
# switch:
#   - switch.onoff_sonoff1
#   - switch.onoff_sonoff2
# battery:
#   - none
#
#
import appdaemon.plugins.hass.hassapi as hass
class Auditalexa(hass.Hass):
    def initialize(self):
# get vars
        self.trigger=self.args["trigger"]
        self.alexa = self.args["notify"]
# check if trigger switch triggered
        self.listen_state(self.auditalexa,self.trigger,new="on")
    def auditalexa (self, entity, attribute, old, new, kwargs):
# get vars 
        title=self.args["title"]
        it = self.args["temp-inside"]
        ot = self.args["temp-outside"]
# check if vars exist or set to none
        if it == "none" :
            it = ""
        if ot == "none" :
            ot = ""
# replace . with word "point" and add the word "degrees" so alexa temperature correctly
        if it != "" :
            it = "Inside temperature is " + self.get_state(it) + " degrees"
            it = it.replace("."," point ")
        if ot != "" :
            ot = "Outside temperture is " + self.get_state(ot) + " degrees"
            ot = ot.replace("."," point ")
#setup lists for Lights (li) switches (sw) and batteries (bt) 
        li = []
        sw = []
        bt = []
#get friendly name and state from device and add to list
        for entity in self.args["light"]:
# if var set to none skip and append none to list
            if entity != "none" :
                li.append(self.friendly_name(entity) + " " + self.get_state(entity))
            else :
                li.apend("none")
#get friendly name and state from device and add to list                
        for entity in self.args["switch"]:
#if var set to none skip and append none to list
            if entity != "none" :
                sw.append(self.friendly_name(entity) + " " + self.get_state(entity))
            else :
                sw.append("none")
#get friendly name and state from device and add to list 
        for entity in self.args["battery"]:
#if var set to none skip and append none to list
            if entity != "none" :
                temp = self.friendly_name(entity) + " " + self.get_state(entity) + " persent charged"
# replace . for point to help alexa speak correctly
                temp = temp.replace("."," point ")
                bt.append(temp)
            else :
                battery.append("none")
#create  message for alexa to speak add , to pause speech 
        mess = title + "," + it + "," + ot + ","
# append message for lights
        for entity in li :
            if entity != "none" :
                mess = mess + entity + ","
# append message for switches
        for entity in sw :
            if entity != "none" :
                mess = mess + entity + ","
# append message for battries
        for entity in bt :
            if entity != "none" :
                mess = mess + entity + ","
#add closing message
        mess = mess + title + "completed"
# Alexa notify unable to work with white spaces replace spaces with _        
        mess = mess.replace(" ","_")
# send notify to alexa 
        self.notify(mess,name = self.alexa)    
# turn off trigger switch
        self.turn_off(self.trigger)
1 Like

If you then create a routine linked to the script you can ask something more sensible. The lounge temperature one I posted on another thread is officially “Alexa, turn on lounge temperature” but I have added it to a routine which is called by “Alexa, what is the lounge temperature”, she does reply “OK” and then a second later reads from the script.

I know it’s a bit of fudge, but I wanted a generic script to tell me the state of things . Grew up with Star Trek , and it’s a bit cool to ask the state of a room. Have added “none” options so it’s fairly adaptable and dead simple to change the script

Really need a pause option on the speech. Tried to pause things by splitting the messages with a run_in() command and delaying the replies by a number of seconds.

This works well as it gives a more natural reply , but it make it impossible to shut her up !! The comma gives a slight pause but the python script ignores multiple , so its a bit of a gabble, any ideas ?

Updated script to use

No change in functionality, slightly better pauses in speech.

#
# Audit feature to get Alexa to announce HA states for :
#
#    Inside Temperature 
#    Outside Temperature 
#    Lights
#    Switches
#    Batteries
#
# Program requires the following parameters
#
#    Title: Name Alexa announces eg Living room Audit
#    Trigger: Switch to trigger program 
#    Device: Name of media player
#    Temp-Inside: Name of sensor
#    Temp-Outside: Name of sensor
#    Light: list of lights
#    Switch: List of switches
#    battery: list of sensors with battery levels
#
# Title,Trigger and Device parameters are mandatory, other parameters that not required must be set to none    
#
# Example config 
#
# AuditAlexa:
# module: AuditAlexa
# class: Auditalexa
# title: "Living Room Audit"
# trigger: "input_boolean.audit_light"
# device : "media_player.lr_dot"
# temp-inside: "sensor.temperature_158d0001b9205b"
# temp-outside: "sensor.dark_sky_temperature"
# light:
#  - light.living_room_lights
#  - light.dining_room_lights
#  - light.gateway_light_34ce0081452d
# switch:
#  - switch.onoff_sonoff1
#  - switch.onoff_sonoff2
# battery:
#  - none
#
#
import appdaemon.plugins.hass.hassapi as hass
class Auditalexa(hass.Hass):
    def initialize(self):
# get vars
        self.trigger=self.args["trigger"]
        self.alexa = self.args["device"]
# check if trigger switch triggered
        self.listen_state(self.auditalexa,self.trigger,new="on")
    def auditalexa (self, entity, attribute, old, new, kwargs):
# get vars 
        title=self.args["title"]
        it = self.args["temp-inside"]
        ot = self.args["temp-outside"]
# check if vars exist or set to none
        if it == "none" :
            it = ""
        if ot == "none" :
            ot = ""
# replace . with word "point" and add the word "degrees" so alexa temperature correctly
        if it != "" :
            it = "Inside temperature is " + self.get_state(it) + " degrees"
            it = it.replace("."," point ")
        if ot != "" :
            ot = "Outside temperture is " + self.get_state(ot) + " degrees"
            ot = ot.replace("."," point ")
#setup lists for Lights (li) switches (sw) and batteries (bt) 
        li = []
        sw = []
        bt = []
#get friendly name and state from device and add to list
        for entity in self.args["light"]:
# if var set to none skip and append none to list
            if entity != "none" :
                li.append(self.friendly_name(entity) + " " + self.get_state(entity))
            else :
                li.apend("none")
#get friendly name and state from device and add to list                
        for entity in self.args["switch"]:
#if var set to none skip and append none to list
            if entity != "none" :
                sw.append(self.friendly_name(entity) + " " + self.get_state(entity))
            else :
                sw.append("none")
#get friendly name and state from device and add to list 
        for entity in self.args["battery"]:
#if var set to none skip and append none to list
            if entity != "none" :
                temp = self.friendly_name(entity) + " " + self.get_state(entity) + " persent charged"
# replace . for point to help alexa speak correctly
                temp = temp.replace("."," point ")
                bt.append(temp)
            else :
                battery.append("none")
#create  message for alexa to speak add , to pause speech 
        mess = title + "," + it + "," + ot + ","
# append message for lights
        for entity in li :
            if entity != "none" :
                mess = mess + entity + ","
# append message for switches
        for entity in sw :
            if entity != "none" :
                mess = mess + entity + ","
# append message for battries
        for entity in bt :
            if entity != "none" :
                mess = mess + entity + ", ."
#add closing message

        mess = mess + title + "completed"
# send tts to alexa 
        self.call_service('media_player/alexa_tts', entity_id=self.alexa, message=mess) 

# turn off trigger switch
        self.turn_off(self.trigger)

Hi,

I am trying to follow your implementation but I got a bit stuck.

I am new to Home Assintant so if you could help me a bit would be great.

I installed AppDaemon addon in Hassio and I have pasted your code in a new .py file in the appdaemon/apps folder and added the config to appdaemon.yaml.

I have also created a routine in Alexa that triggers a virtual lamp I have exported from Hassio using a virtual hue bridge.

I am not sure now how i trigger your python script.

Does it get triggered automatically when the state of the trigger from the apps.yaml changes? or I need to create some sort of automation?

Also on the AppDaemon administrator page the app state is terminated…is that supposed to be like that?

Thanks a lot

This is a very old script It has been replaced by

The original alexa TTS has been replaced by

I no longer run this script . Try the above , if you need help , please let me know :slight_smile: