Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import random
- import datetime
- import telepot
- import json
- from requests import get
- headers = {'x-ha-access': 'password',
- 'content-type': 'application/json'}
- # Devices to load info from
- devices = ['binary_sensor.thermostaat_current_operation','thermostat.thermostaat','sensor.netatmo_buiten_temperature','sensor.netatmo_binnen_co2', 'sensor.netatmo_binnen_noise','sensor.netatmo_binnen_co2','sensor.netatmo_binnen_temperature','sensor.netatmo_binnen_humidity','sensor.netatmo_binnen2_co2','sensor.netatmo_binnen2_temperature','sensor.netatmo_binnen2_humidity','sensor.slaapkamer_eva','sensor.slaapkamer_eva_2']
- #Get info from device
- def get_info (device_id):
- url = 'http://10.0.1.59:8124/api/states/' + str(device_id)
- response = get(url, headers=headers)
- json_response = json.loads(response.text)
- return json_response
- def handle(msg):
- chat_id = msg['chat']['id']
- command = msg['text']
- print 'Got command: %s' % command
- if command == '/roll':
- bot.sendMessage(chat_id, random.randint(1,6))
- elif command == '/time':
- bot.sendMessage(chat_id, str(datetime.datetime.now()))
- elif command == '/start':
- bot.sendMessage(chat_id, 'hola!')
- elif command == '/states':
- states = []
- for s in devices:
- device_data = get_info(s)
- state= str(device_data['attributes']['friendly_name'] + ": " + device_data['state'])
- states.append(str(state))
- joined_states = "\n".join(states)
- bot.sendMessage(chat_id, str(joined_states))
- bot = telepot.Bot('bottokenidthing')
- bot.message_loop(handle)
- print 'I am listening ...'
- while 1:
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement