Google Home->IFTTT(google Assistant,Telegram)->Telethon->H.A.->Denon Receiver

I changed my setup so I am changing my notes on this thread.

I bypassed the android phone and now I am using telegram with telethon and a small python script(attached below) running on the same server as home-assistant. IFTTT is the same calls to telegram, just the telethon is listening and not the phone. I used this for the last week with no issues and very happy with the performance. Sometimes the receiver is changed, before the google home says “OK”, very FAST


Old unedited notes:
I am trying to connect google home to my denon receiver to change the source, with out a harmony hub. I would have used the hue emulator, but that does not work any more. So my plan is to go from Google Home->IFTTT->Android SMS->OLD Andorid Phone->Hangouts->Tasker(with curl)->H.A.->Denon Receiver. Sounds complicated:-)

Everything is working in a proof of concept except getting the sms message to tasker. Tasker can intercept a sms easily, but hangouts is a being a pain. I can not use a pure sms since my old phone has no sim card and does not have a real SMS so I am trying to use autoIntercept with hangouts which is the biggest pain. Anyone have a clue how to get a SMS to tasker, or anyother way to get google home to send some message to the phone?

FYI:
I will not open a port in my firewall for security reasons.
Eventually I might buy a harmony hub, but not now.
Running HA on debian.

Use join component from joao apps

Thanks, I going to try everything with AutoVoice and see if that works and no need for ifttt and sms.

Rather than using google hangouts, what about telegram?

Or better yet, ditch the old phone altogether and control via email?

Telegram is better than hangouts, but having an issue where every few messages tasker does not respond to the command. Not sure why. Any clue?

As for email, I want to control my denon receiver with google home and I did not want to have a long wait for the email to come through and was thinking a message service would be faster.
Not worth buying a harmony hub for this. (time spent on this is not an issue, yet)

Could you not have IFTT contact HA directly? It could trigger an event and then that event could cause an automation in HA? This is quite easy…

Oh - just read your comment about nto wanting to open a port.

My laziness is worth less than my security. When I need to I will just get up, walk 6 feet, and use my toe to select the correct source on the receiver. :slight_smile:

I finally finished and it is working. Takes about 5-10 seconds, but it works. So I was able to get this working by using telegram and Notification Listener.

Google Home->IFTTT(google Assistant,Telegram)->OLD Android Phone->Telegram->Notification Listener->Tasker->H.A.->Denon Receiver

Somethings I learned,

  1. IFTTT telegram bot can not talk to my own bots, bots can not talk to each other.
  2. Telegram has an issue where notification would not show, needed to uninstall and reinstall.
    3, In tasker, http post with json works ok with HA
  3. Turn off battery savers

Glad you got the telegram route figured out, and I appreciate not wanting to open up ports.

Not tried it for automation, but in general, I think gmail-to-gmail is pretty instant. However, I’m not sure what the detection time would be on the receiving end (using tasker?) for realizing the email has arrived.

  1. Given https://home-assistant.io/components/google_assistant/ are the steps you did needed any more?

  2. Even if they aren’t, would you share the details/configs of each component? Might be interesting.

Thanks!

i tried gmail through ifttt and i noticed after a few emails, the emails are slightly slowed down. I was thinking there is a gmail flood control to slow down emails if fired to fast. Not sure if that is true and there was network issues. That is why i went with telegram.

This is my simple request, just to turn off the receiver, I did make a volume control using ingredients , too, but I will not get into that here.

Step 1 Make and ifttt for google assistant to telegram.

Step 2, install telegram, notification listener, tasker on phone
Create tasker profile:


create task to kick of task

call a N.A. url to execute the automation



1 Like

You might skip the android phone by just using the telegam chatbot integration of hass? This would make the flow:

GH -> IFTTT -> Telegram -> Hass

2 issues, please tell me if I am wrong.

The chatbot is a bot and not a user. Telegram bots can not talk to another bot and IFTTT uses a bot to send out it messages. If chatbot is a real user and not a bot, then it could work.

I need to open a port in my firewall and at the moment I do not want too.

So I was able to remove the android phone and tasker. I found a python library that runs a telegram client I can script against. Library is telethon. After a few hours and less than 100 lines of code most things seem like it is working and it is much faster, under a second from when google says ok to receiver update.

I am running telethon on the same linux box as hass other than learning python in an hour or 2 all seems easy. http://telethon.readthedocs.io/

#!/usr/bin/env python3.4
from telethon import TelegramClient
from telethon.tl.types import UpdateNewMessage, PeerUser, UpdateShortMessage
import requests, json
import datetime
import sys
import logging
logging.basicConfig(filename='auto-home.log',level=logging.WARNING,format='%(asctime)s %(levelname)s: %(message)s')
logging.warning('Starting v2')

# Use your own values here
api_id = 111111
api_hash = '22222222222222222222'
phone = '+3333333333333333'
hass_url = 'http://localhost:8123/api/services/'
hass_pw='444444444'
valid_in_comming_users='5555555555'



logging.warning('api_id:   ' + str(api_id))
logging.warning('api_hash: ' + api_hash)
logging.warning('phone:   ' + phone)
logging.warning('hass_url: ' +hass_url)
logging.warning('hass_pw:  ' +hass_pw)
logging.warning('valid_in_comming_users:. ' +valid_in_comming_users)

def callHass(uid,data):
  try:
  
logging.warning('Starting web:  ' + uid)
  
if str(uid) != valid_in_comming_users: 
	return
logging.warning('Starting web:  ' + data)
msg = data.split(" ",2)

headers = {'content-type': 'application/json'}

if msg[0] == 'ReceiverFios':
	payload = {'entity_id': 'media_player.receiver','source': 'CBL/SAT'}
	device = 'media_player/select_source'
elif msg[0] == 'ReceiverChromeCast':
  payload = {'entity_id': 'media_player.receiver','source': 'CHROMECAST'}
  device = 'media_player/select_source'
elif msg[0] == 'ReceiverVolume':
  payload = {"entity_id": "media_player.receiver", "volume_level": "." + msg[1] }
  device = 'media_player/volume_set'
else:
  logging.warning('nothing')
  return
   
url = hass_url + device + '?api_password=' +hass_pw 
logging.warning (url) 
logging.warning (payload)
r = requests.post(url, data=json.dumps(payload), headers=headers)
logging.warning (r)
logging.warning ('Device Updated, Cool!!!')

  except:
  logging.warning("DEVICE Unexpected error:")
  logging.warning("Unexpected error:", sys.exc_info()[0])

#test something on start
callHass(valid_in_comming_users,'ReceiverVolume 21')
callHass(valid_in_comming_users,'ReceiverVolume 22')

def callback(update):
try:
  logging.warning ('=================================================')
  logging.warning (update)
  logging.warning('EOM!!')
  if isinstance(update,UpdateNewMessage):
    logging.warning('Type: UpdateNewMessage!')
    logging.warning('Message:', update.message.message)
    logging.warning('From:',update.message.from_id)
    callHass(str(update.message.from_id),update.message.message)
  elif isinstance(update,UpdateShortMessage):
    logging.warning('Type: UpdateShortMessage!')
    logging.warning('Message:', update.message)
    logging.warning('From:',update.user_id)
    callHass(str(update.user_id),update.message)
  else:
    logging.warning('Type: ???!')
  logging.warning('Done!')
except:
  logging.warning("Unexpected error:", sys.exc_info()[0])
  raise

client = TelegramClient('anon', api_id, api_hash,update_workers=1, spawn_read_thread=False)
client.start(phone = phone)
client.add_update_handler(callback)
client.idle()  # ends with Ctrl+C
client.disconnect()

nice work @marcw, I would like to try to write and AppDaemon service to do this gateway between IFTTT and HA

should not be too complicated https://appdaemon.readthedocs.io/en/stable/

Hello @etreus, I’m interested in doing this in AppDaemon, can we work together?
Let me know how to keep in touch, I started following you on github :wink:

Would be nice but right now I can spend just a couple of hours per months on HA stuff.
I did some test using the telegram API and requests and flask modules and for now , lets continue on the other thread did you make about AD.

Yes, in the meantime I managed to do it.
I installed telethon libraries using the AD addon in hassio and then was able to login and interact with my Telegram user :slight_smile:

This way I can intercept IFTTT push messages and react in Home Assistant.