homeassistant:
group:
janet_settings:
name: Settings
view: yes
icon: mdi:tune
entities:
- group.janet_notification_modes
- group.janet_notification_notifications
- group.janet_notification_settings
- group.janet_notification_skills
janet_notification_modes:
name: Modes
entities:
- input_boolean.janet_guest_mode
- input_boolean.janet_alert_mode
janet_notification_notifications:
name: Notifications
entities:
- input_boolean.janet_speech_notifications
- input_boolean.janet_text_notifications
janet_notification_settings:
name: Settings
entities:
- input_select.janet_notification_media_player
- input_number.janet_notification_volume
- input_number.janet_notification_witty
janet_notification_skills:
name: Skills
entities:
- automation.janet_new_device_connected
- automation.janet_update_available
- automation.janet_start_up
- automation.janet_shut_down
input_boolean:
janet_guest_mode:
name: Guest Mode
icon: mdi:account-multiple
initial: off
janet_alert_mode:
name: Alert Mode
icon: mdi:bell
initial: off
janet_speech_notifications:
name: Speech Notifications
icon: mdi:bell-outline
initial: on
janet_text_notifications:
name: Text Notifications
icon: mdi:message-text-outline
initial: on
input_number:
janet_notification_volume:
name: Volume
icon: mdi:volume-high
min: 0.0
max: 1.0
step: 0.01
initial: 1.0
janet_notification_witty:
name: Witty
icon: mdi:auto-fix
min: 0
max: 100
step: 1
initial: 80
input_select:
janet_notification_media_player:
name: Source
icon: mdi:speaker
options:
- “Google_Assistant”
- “HA”
- “Living Room TV 2”
initial: “Google_Assistant”
script:
######################################################################################################
within janet_speech_engine the string message is generated with the use of macro’s.
######################################################################################################
janet_speech_engine:
sequence:
- service: script.janet_notification_hub
data_template:
#TODO
media_player: >-
{%- for device in states.media_player -%}
{%- if device.name == states.input_select.janet_notification_media_player.state -%}
{{ device.entity_id }}
{%- endif -%}
{%- endfor -%}
speech_message: >-
{%- macro greeting() -%}
{% set greeting = [
"Hello, ",
"Heya! ",
"Hey Guys! ",
"Hey there! ",
"Hi, ",
"Hi there, "
] %}
{{ greeting|random }}
{%- endmacro -%}
{%- macro inform() -%}
{% set inform = [
"I just want to inform you that ",
"I just want to let you know that ",
"You asked me to inform you when ",
"I thought you'd like to know that "
] %}
{{ inform|random }}
{%- endmacro -%}
{%- macro introduction() -%}
{% set introduction = [
"I'm an informational delivery system, I literraly know everything. ",
"I'm sort of the janitor around here. ",
"I'm like a walking database. You can ask me about the creation of the universe... or history. ",
"Every time a Janet is rebooted, she increases her social awareness and abilities. I might be the most advanced Janet in the universe. ",
"I can be your therapist if you want. ",
"I have now been fully activated. ",
"Welcome to your new Janet. Janets are brought to you by the makers of light, darkness, and everything. ",
"To activate your Janet, press nose for three seconds. ",
"I'm very high in potassium. Like a banana! ",
"Happy to meet you. I will help you make the perfect neighborhood. Would you like to get started? ",
"I build and operate the neighborhood. You can ask me anything. For example, if you'd like me to stop calling you silly billy, just say so. "
] %}
I'm Janet. {{ introduction | random }}
{%- endmacro -%}
{%- macro unknown() -%}
{% set unknown = [
"Hmm, I don't know ",
"I wish I knew ",
"My programming prohibits me from telling you "
] %}
{{ unknown | random }}
{%- endmacro -%}
{%- macro error() %}
{% set error = [
"Fun fact: Janet is me! ",
"I don't understand. Given the situation it's far safer to initiate the self-destruct. ",
"If I stand next to a powerful array of magnets, I do get pretty loopy. ",
"I don't know what just happened, but I'm happy you're happy. ",
"A new Janet will need to be procured in order to return the Neighborhood to functionality. ",
"That glitch appears to have been limited to this building. ",
"I don't seem to be getting better. ",
"Here's a cactus! ",
"I tried to eat frozen yogurt. It looked so good, but I'm not supposed to eat anything, so there was a little earthquake. ",
"Look at us. Couple old pals, trying to make our way in this crazy world... that I built... Two peas in a pod. One of whom needs to kill the other one immediately. Come on. Kill me! ",
"What I really want is to stay and serve the neighborhood, but due to my glitching I'm putting him and everyone else at risk. So it looks like it's... Adios, Janeto! ",
"I know what you have to do now. Kill me! Sorry. I say everything in a cheery manner but in this case it may be inappropriate, so I'll try again. You have to kill me. ",
"Hi guys! I'm broken! ",
"Please don't make a big deal about turning me into a marble forever, i'm broken. ",
"Does not compute. Does not compute. I'm just kidding. I mean, it doesn't compute, but I'm not gonna explode or anything. "
] %}
{{ error | random }}
{%- endmacro -%}
{%- macro update() -%}
{% set update = [
"There have been 25 generation of Janet. Each new update of Janet gains more wisdom and social abilities. Fun fact: the first Janet had a clicking wheel! ",
"I read all Google's eight hundred and sixty one thousand references on Home Assistant these last 3 milliseconds, and I found some new skills! ",
"I just leisurely reread all of human history, there was even some new content! ",
"So I found an update. That's the good news. The bad news is I seem to be losing my ability to sustain object permanence, so it's sort of a glass-half-full, glass-stops-existing-in-time-and-space kinda deal. "
] %}
{{ update | random }}
{%- endmacro -%}
{%- macro location_not_home() -%}
{% set not_home = [
" is going somewhere. ",
" is currently not in this neighbourhood. ",
"'s location is not in my database. "
] %}
{{ not_home | random }}
{%- endmacro -%}
{%- macro location_inquiry( person, not_home ) -%}
{%- for device in states.device_tracker -%}
{%- if device.name == person -%}
{%- set location = device.state -%}
{% if location == "not_home" %}
{{ person }} {{ not_home }}
{%- else -%}
{{ person }} is at {{ location }}.
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- macro bad_weather() -%}
{% set rain = [
" You might want to change your schedule. ",
" Maybe you should ask for a ride. ",
" It's no weather to be outside. ",
" All those poor people outside... "
] %}
{{ rain | random }}
{%- endmacro -%}
{%- macro rain_warning( bad_weather ) -%}
{% set rain = [
Event ~ " there will be " ~ WeatherRain ~ " rain. " ,
Event ~ " I predict " ~ WeatherRain ~ " rain. ",
" I think that " ~ Event ~ " there will be " ~ WeatherRain ~ " rain. "
] %}
{{ rain | random }}{{ bad_weather }}
{%- endmacro -%}
{%- macro okay()-%}
{% set okay = [
"Done! I love you guys. ",
"Extraordinarily bad idea. Oh well.. ",
"Funny, I was just about to do that. ",
"Here you go. ",
"I'll do that. ",
"Ofcourse! ",
"Ofcourse! Glad to help. ",
"Of course, silly billy. ",
"OK ",
"Okay ",
"Okay, can we not do this in front of my friends? ",
"Okie-dokie ",
"Sure ",
"Sure thing! ",
"There. Happy to help. ",
"There you go! ",
"Okay. I've hacked into the mainframe. ",
"Okay. I've hacked into the mainframe. Kidding. I can't hack into the mainframe. Technically, I am the mainframe. ",
"I will not. It is literally impossible for me to do that. Just kidding. ",
"I couldn't do this 800 reboots ago, but apparently now I can. "
"Yup. Bye! "
] %}
{{ okay|random }}
{%- endmacro -%}
{%- macro bye() -%}
{% set bye = [
"Adios! ",
"Bye Guys! ",
"See ya! " ,
"See you later. ",
"Untill next time!"
] %}
{{ bye | random }}
{%- endmacro -%}
{%- macro shut_down() -%}
{% set shut_down = [
"I'll be gone, you'll get a new Janet, and everything will go back to normal. Well, not for me, I'll be a lifeless marble floating through space, but you will be back to normal.",
"Self-destruct time... Don't worry, I won't feel any pain or anything. ",
"If it's okay with you, I'm gonna go to my void for a little while. I just need to spend some time alone and focus on myself. ",
"Shutting down. I'll be about as dead as I can be. Kind of like I'm in power-saver mode. ",
"I'm in danger of total collapse. Fun fact! Mathematically, I'm equally likely to either implode or explode. "
] %}
{{ shut_down | random }}
{%- endmacro -%}
{% set chance = states.input_number.janet_notification_witty.state | round %}
{%- macro witty( sentence, witty ) -%}
{% set number = (range(0, 100)|random) %}
{% if number <= chance %}
{{ sentence }}
{% endif %}
{%- endmacro -%}
{%- macro new_device( introduction ) -%}
{% set new_device = [
introduction~"I don't know your name yet, so for now i will call you "~person,
"We have a visitor! Nice to meet you "~person~". "~introduction,
"Welcome "~person~"! Or is that not your real name? "~introduction
] %}
{{ new_device | random }}
{%- endmacro -%}
{%- macro alarm_clock_check() -%}
Alarm clock weekday status is {{ states('input_boolean.alarmclock_wd_enabled') }} at {{ states('sensor.alarmclock_wd_time_template') }} and alarm clock weekend status is {{ states('input_boolean.alarmclock_we_enabled') }} at {{ states('sensor.alarmclock_we_time_template') }}.
{%- endmacro -%}
{%- macro security_check() -%}
S1C alarm status is {{ states('sensor.key_fob') }}. SSH alarm status is {{ states('alarm_control_panel.ssh') }}. Office camera motion status is {{ states('switch.office_camera_motion') }} and office camera record status is {{ states('switch.office_camera_alarm') }}.
{%- endmacro -%}
{%- macro system_check() -%}
CPU temperature is {{ states('sensor.cpu_temp') }} °C. Processor is running at {{ states('sensor.processor_use') }} %. Memory used is {{ states('sensor.memory_use_percent') }} %. Disk used is {{ states('sensor.disk_use_percent_') }} % and your last reboot is {{ states('sensor.ha_last_reboot') }}.
{%- endmacro -%}
{%- macro Home_Assistant_check() -%}
Home Assistant installed version is {{ states('sensor.installed_ha_version') }}. Database size is {{ states('sensor.ha_db_size') }} Megabytes. Uptime running is {{ states('sensor.ha_uptime') }}. SSL certificate is expiring in {{ states('sensor.ssl_cert_expiry') }} days and currently {{ states('sensor.connected_clients') }} clients are connected to Home Assistant.
{%- endmacro -%}
{# ********************************************* #}
{# ******** Start the Speech routines ******** #}
{# ********************************************* #}
{% if call_alarm_clock_check == 1 %}
{{ alarm_clock_check() }}
{% endif %}
{% if call_greeting == 1 %}
{{ greeting() }} {% endif %} {% if call_introduction == 1 %} {{ introduction() }} {% endif %} {% if call_update == 1 %} {{ update() }} {% endif%} {% if call_okay == 1 %} {{ okay () }} {% endif %} {% if call_inform == 1 %} {{ inform() }} {% endif %} {% if call_location_inquiry == 1 %} {% set location = location_inquiry( person, location_not_home() ) %} {% set count = location | length %} {% if count <= 10 %} {{ unknown() }}where {{ person }} is. {{ witty( error(), chance ) }} {% else %} {{ location }} {% endif %} {% endif %} {% if call_rain_warning == 1 %} {{ rain_warning( witty ( bad_weather(), chance ) ) }} {% endif %} {{ CustomMessage }} {% if call_bye == 1 %} {{ bye() }} {% endif %} {% if call_shut_down == 1 %} {{ witty( shut_down(), chance) }} {% endif %} {% if call_new_device == 1 %} {{ new_device( witty( introduction(), chance) ) }}
{% endif %}
{% if call_security_check == 1 %}
{{ security_check() }}
{% endif %}
{% if call_system_check == 1 %}
{{ system_check() }}
{% endif %}
{% if call_homeassistant_check == 1 %}
{{ homeassistant_check() }}
{% endif %}
{% if call_greeting == 1 %}
{{ greeting() }}
{% endif %}
{% if call_introduction == 1 %}
{{ introduction() }}
{% endif %}
{% if call_update == 1 %}
{{ update() }}
{% endif%}
{% if call_okay == 1 %}
{{ okay () }}
{% endif %}
{% if call_inform == 1 %}
{{ inform() }}
{% endif %}
{% if call_location_inquiry == 1 %}
{% set location = location_inquiry( person, location_not_home() ) %}
{% set count = location | length %}
{% if count <= 10 %}
{{ unknown() }}where {{ person }} is. {{ witty( error(), chance ) }}
{% else %}
{{ location }}
{% endif %}
{% endif %}
{% if call_rain_warning == 1 %}
{{ rain_warning( witty ( bad_weather(), chance ) ) }}
{% endif %}
{{ CustomMessage }}
{% if call_bye == 1 %}
{{ bye() }}
{% endif %}
{% if call_shut_down == 1 %}
{{ witty( shut_down(), chance) }}
{% endif %}
{% if call_new_device == 1 %}
{{ new_device( witty( introduction(), chance) ) }}
{% endif %}
- service: input_boolean.turn_off
data:
entity_id:
- input_boolean.janet_alert_mode
######################################################################################################
janet_notification_hub is the bridge between the speech_engine and the processing units.
######################################################################################################
janet_notification_hub:
sequence:
- service: script.janet_speech_processing
data_template:
media_player: >-
{{ media_player }}
speech_message: >-
{{ speech_message }}
- service: script.janet_text_processing
data_template:
speech_message: >-
{{ speech_message }}
######################################################################################################
Within janet_speech_processing the TTS-service is called.
######################################################################################################
janet_speech_processing:
sequence:
- condition: and
conditions:
- condition: or
conditions:
- condition: time
after: ‘07:00:00’
before: ‘23:00:00’
- condition: state
entity_id: input_boolean.janet_alert_mode
state: ‘on’
- condition: state
entity_id: input_boolean.janet_speech_notifications
state: ‘on’
- condition: or
conditions:
- condition: state
#TODO
entity_id: group.people
state: ‘home’
- condition: state
entity_id: input_boolean.janet_guest_mode
state: ‘on’
#TODO
- wait_template: “{{ not is_state( media_player, ‘playing’) }}”
timeout: 00:00:30
- service: media_player.volume_set
data_template:
entity_id: >
{{ media_player }}
volume_level: >-
{{ states.input_number.janet_notification_volume.state }}
- service: tts.google_say
data_template:
entity_id: >
{{ media_player }}
message: >-
{{ speech_message | replace("\n","") | replace(" ","") | replace(" "," ") }}
######################################################################################################
Within janet_text_processing the notify-service is called.
######################################################################################################
janet_text_processing:
sequence:
- condition: state
entity_id: input_boolean.janet_text_notifications
state: ‘on’
- service: notify.Janet
data_template:
#TODO
title: "Janet:"
message: >-
{{ speech_message | replace("\n","") | replace(" ","") |
replace("eight hundred and sixty one thousand","861.000") }}
- service: notify.ios_nhatphat_6s
data_template:
title: "Janet:"
message: >-
{{ speech_message | replace("\n","") | replace(" ","") | replace("eight hundred and sixty one thousand","861.000") }}
- service: tts.google_say
data_template:
title: "Janet:"
message: >-
{{ speech_message | replace("\n","") | replace(" ","") | replace("eight hundred and sixty one thousand","861.000") }}