Janet (The Good Place)

Also, if I try and trigger the new device automation from the front-end I get this error

2018-01-17 21:42:33 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/sandbox.py", line 385, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 336, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 426, in action
    yield from script_obj.async_run(variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 80, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 76, in _data_template_creator
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 76, in <dictcomp>
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 78, in _data_template_creator
    return value.async_render(variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined

OK, getting closer. After implementing all of your most recent changes on github I am now getting text alerts on startup. Still nothing via voice yet though.

@CBRHerms trigger undefined makes sense, because the automation is using a new found device_tracker. You can’t manually trigger this automation.

looking through the code on github i noticed some things were forgotten when it was made into a package. I’m walking through the code atm.

if text is working, speech should be working too. Turn on alert mode ( TTS is turned off from 23:00 - 07:00 unless alert mode is on )

It’s only 22:00 here, so speech should be working without alert mode. Having enabled alert mode and tried to trigger the start up automation, it seems to be disabled when the automation runs and I just receive text notification.

Amazing Project!! Good Job!!

@davemc Hmm… janet_speech_processing is using another condition at line 390. Either group.location should be at state “home” or guest mode should be on. ( I have my phone and my wife’s phone in that group ).

That was it :smiley:

Now to get playing with this. Thanks a bunch. Awesome work!

1 Like

update: script.janet_speech_engine now dynamically sets the media_player. You still have to add all the media_players friendly names to the input_select.media_player though.

ps: If anyone knows how to dynamically:

  • add options to input_select,
  • add entities to groups,

please let me know. That would have a huge effect on the amount of configurations needed to use this package.

1 Like

Would you advice the automation of rain after work for darksky?

From your rain: after work automation

  1. I try to change the sensor state to darksky it doesn’t work.

{{ states.sensor.buienradar_precipitation_forecast_total.state + " " + states.sensor.buienradar_precipitation_forecast_total.attributes.unit_of_measurement }}

{{ states.sensor.dark_sky_precip_intensity.state + " " + states.sensor.dark_sky_precip_intensity.attributes.unit_of_measurement }}

  1. “Event”: “after work” <== where the “after work” come from? is it from the name of the automation or?

@Sunonline

  • Event: after work is a string, it’s a parameter.
  • keep in mind that when it comes to templating you have to use data_template instead of data.
  • In your HA client go to templating and make sure your sensor state works there, then copy it into the automation
1 Like

When the TTS is played via the speakers, it seems like there is a gap between the greeting, inform etc. Like there is a new sentence. However looking at the text notifications this is not the case. To solve this, I’ve removed all the linebreaks from the speech routines, so it’s now like this.

        {# ********************************************* #}
        {#  ******** Start the Speech routines ********  #}
        {# ********************************************* #}

        {% 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 %} 

That seems to sort it and it now sounds like the TTS voice is a bit more natural.

I’ve added an automation that checks a google calendar to see which waste recycling bin is getting emptied and announces a reminder via Janet for me to put it out for collection if it isn’t already out yet.

2 Likes

@davemc I didn’t realise the newlines and tabs had an effect on TTS. I removed them for the notification but not for the TTS command. This is fixed in the Github now

Furthermore, would you like to share your automation for the bins? This could provide the rest of us with more inspiration of how to use Janet :wink: thanks!

1 Like

Works fine now with rain after work automation.
I have change to temperature and hourly summary from darksky. the data template is correct but wrong indent ^^

Secondly from Mr.davemc. I have also remove the linebreaks and the speech is more smoother ^^ Thank you very much.

1 Like

My automation for the bin is a bit of a workaround, as I already had text notification for it every 3 hours on the day before collection, with actionable buttons on the notifications, so that I can press a button to say the bin is now out, so I don’t receive more notifications once I have already put the bin out.

So for my regular non-janet automation I have

##### Check days to bin out sensor and send alert if bin isn't out (boolean) ######

- alias: 'bin alert'
  id: 'alert_putbinout'
  trigger:
    platform: numeric_state
    entity_id: sensor.nextbinout2
    below: 0.8
  condition:
    condition: state
    entity_id: input_boolean.bin_out
    state: 'off'
  action:
  - service: automation.turn_off
    entity_id: automation.bin_alert
  - service: notify.notify_pixel2
    data_template:
      title: "Bin at 7am"
      message: "The {{states.calendar.bin_schedule.attributes.message}} bin gets emptied at 7am and isn't out yet."
      data:
        actions:
          - action: "binisout"
            title: "Bin is Out"
          - action: "ok"
            title: "Snooze"
  - delay:
      minutes: 180
  - service: automation.turn_on
    entity_id: automation.bin_alert

- alias: 'Bin is Out Alert Clicked'
  trigger:
    platform: event
    event_type: html5_notification.clicked
    event_data:
     action: binisout
  action:
    service: input_boolean.turn_on
    data:
        entity_id: input_boolean.bin_out

Then for my Janet one I have this…

##############################################################################
###  BIN GETS EMPTIED TOMORROW ##########
##############################################################################

  - alias: "Janet Bin Due Out"
    trigger:
      platform: numeric_state
      entity_id: sensor.nextbinout2
      below: 0.8
    condition:
      condition: state
      entity_id: input_boolean.bin_out
      state: 'off'

    action:
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.janet_alert_mode

 ### Turn off Janet text notifications as I already get HTML5 actionable text notifications ####

      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.janet_text_notifications

      - service: script.janet_speech_engine
        data:
          call_greeting: 1
          call_inform: 1
        data_template:
          CustomMessage: >-
           the {{states.calendar.bin_schedule.attributes.message | lower}} bin gets emptied tomorrow and isn't out yet.
 ### Turn Janet text notifications back on after Janet notification sent ####
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.janet_text_notifications

Any questions feel free to ask. I’m planning on tidying all my config up shortly and putting it on github.

1 Like

Thank you so much for sharing. I am really noob to this. But I really love HA and this community ^^

@Lentron hello how are you? i have a doubt
i am trying to use your project, and i can say this is great.
But, when i use example:

image

when TTS finish spoke, my input boolean ALERT MODE go to OFF, and i have to put on again , if i try again the input boolean is gone to off again.
why???

I think the alert mode boolean is to be turned on via an automation for an alert that should never be missed. It is always turned off again after speech is output.

So if you always want speech for a certain automation then you enable it as part of that automation.

1 Like

But can I have the alert mode always activated? What happens if i have always been active?

From line 345 in janet.yaml comment out the following bit to not have alert mode disable itself.

  - service: input_boolean.turn_off
    data:
      entity_id:
        - input_boolean.janet_alert_mode

Yes, but I’d like to know what this is for, actually? What is the intention of using this?