Python json.htm() Examples
The following are 14
code examples of json.htm().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
json
, or try the search function
.
Example #1
Source File: plugin.py From SmartVirtualThermostat with MIT License | 6 votes |
def DomoticzAPI(APICall): resultJson = None url = "http://{}:{}/json.htm?{}".format(Parameters["Address"], Parameters["Port"], parse.quote(APICall, safe="&=")) Domoticz.Debug("Calling domoticz API: {}".format(url)) try: req = request.Request(url) if Parameters["Username"] != "": Domoticz.Debug("Add authentification for user {}".format(Parameters["Username"])) credentials = ('%s:%s' % (Parameters["Username"], Parameters["Password"])) encoded_credentials = base64.b64encode(credentials.encode('ascii')) req.add_header('Authorization', 'Basic %s' % encoded_credentials.decode("ascii")) response = request.urlopen(req) if response.status == 200: resultJson = json.loads(response.read().decode('utf-8')) if resultJson["status"] != "OK": Domoticz.Error("Domoticz API returned an error: status = {}".format(resultJson["status"])) resultJson = None else: Domoticz.Error("Domoticz API: http error = {}".format(response.status)) except: Domoticz.Error("Error calling '{}'".format(url)) return resultJson
Example #2
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 6 votes |
def execute(self, command, params): """Execute an OnOff command.""" domain = self.state.domain protected = self.state.protected if domain not in [domains['sensor'], domains['smokedetektor']]: if domain == domains['group']: url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchscene&idx=' + self.state.id + '&switchcmd=' + ( 'On' if params['on'] else 'Off') else: url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=' + ( 'On' if params['on'] else 'Off') if protected: url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass'] r = requests.get(url, auth=CREDITS) if protected: status = r.json() err = status.get('status') if err == 'ERROR': raise SmartHomeError(ERR_WRONG_PIN, 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id))
Example #3
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 6 votes |
def execute(self, command, params): """Execute a scene command.""" protected = self.state.protected url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchscene&idx=' + self.state.id + '&switchcmd=On' if protected: url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass'] r = requests.get(url, auth=CREDITS) if protected: status = r.json() err = status.get('status') if err == 'ERROR': raise SmartHomeError(ERR_WRONG_PIN, 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id))
Example #4
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 6 votes |
def execute(self, command, params): """Execute a brightness command.""" protected = self.state.protected url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str( int(params['brightness'] * self.state.maxdimlevel / 100)) if protected: url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass'] r = requests.get(url, auth=CREDITS) if protected: status = r.json() err = status.get('status') if err == 'ERROR': raise SmartHomeError(ERR_WRONG_PIN, 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id))
Example #5
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 6 votes |
def execute(self, command, params): """Execute a color setting command.""" if "temperature" in params["color"]: tempRange = self.kelvinTempMax - self.kelvinTempMin kelvinTemp = params['color']['temperature'] setTemp = 100 - (((kelvinTemp - self.kelvinTempMin) / tempRange) * 100) url = DOMOTICZ_URL + '/json.htm?type=command¶m=setkelvinlevel&idx=' + self.state.id + '&kelvin=' + str( round(setTemp)) elif "spectrumRGB" in params["color"]: # Convert decimal to hex setcolor = params['color'] color_hex = hex(setcolor['spectrumRGB'])[2:] lost_zeros = 6 - len(color_hex) color_hex_str = "" for x in range(lost_zeros): color_hex_str += "0" color_hex_str += str(color_hex) url = DOMOTICZ_URL + '/json.htm?type=command¶m=setcolbrightnessvalue&idx=' + self.state.id + '&hex=' + color_hex_str r = requests.get(url, auth=CREDITS)
Example #6
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 6 votes |
def execute(self, command, params): """Execute a EnergyStorge command.""" # domain = self.state.domain # protected = self.state.protected # if domain in (domains['vacuum'], domains['mower']): # url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=' + ( # 'On' if params['charge'] else 'Off') # if protected: # url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass'] # r = requests.get(url, auth=CREDITS) # if protected: # status = r.json() # err = status.get('status') # if err == 'ERROR': # raise SmartHomeError(ERR_WRONG_PIN, # 'Unable to execute {} for {} check your settings'.format(command, # self.state.entity_id))
Example #7
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def execute(self, command, params): """Execute a OpenClose command.""" features = self.state.attributes protected = self.state.protected state = self.state.state if features & ATTRS_PERCENTAGE: url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str( 100 - params['openPercent']) else: p = params.get('openPercent', 50) url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=' if p == 100 and state in ['Closed', 'Stopped', 'On']: # open url += 'Off' elif p == 0 and state in ['Open', 'Stopped', 'Off']: # close url += 'On' else: raise SmartHomeError(ERR_ALREADY_IN_STATE, 'Unable to execute {} for {}. Already in state '.format(command, self.state.entity_id)) if protected: url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass'] r = requests.get(url, auth=CREDITS) if protected: status = r.json() err = status.get('status') if err == 'ERROR': raise SmartHomeError(ERR_WRONG_PIN, 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id))
Example #8
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def execute(self, command, params): """Execute a temperature point or mode command.""" # All sent in temperatures are always in Celsius if command == COMMAND_THERMOSTAT_SET_MODE: if self.state.modes_idx is not None: levels = base64.b64decode(self.state.selectorLevelName).decode('UTF-8').split("|") levelName = [x.lower() for x in levels] if params['thermostatMode'] in levelName: level = str(levelName.index(params['thermostatMode']) * 10) url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.modes_idx + '&switchcmd=Set%20Level&level=' + level r = requests.get(url, auth=CREDITS) else: raise SmartHomeError('notSupported', 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id)) if command == COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT: if self.state.modes_idx is not None: levelName = base64.b64decode(self.state.selectorLevelName).decode('UTF-8').split("|") level = self.state.level index = int(level / 10) if levelName[index].lower() == 'off': raise SmartHomeError('inOffMode', 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id)) elif levelName[index].lower() == 'auto': raise SmartHomeError('inAutoMode', 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id)) elif levelName[index].lower() == 'eco': raise SmartHomeError('inEcoMode', 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id)) url = DOMOTICZ_URL + '/json.htm?type=command¶m=setsetpoint&idx=' + self.state.id + '&setpoint=' + str( params['thermostatTemperatureSetpoint']) r = requests.get(url, auth=CREDITS)
Example #9
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def execute(self, command, params): """Execute an LockUnlock command.""" domain = self.state.domain state = self.state.state protected = self.state.protected if domain == domains['lock']: if params['lock'] == True and state == 'Unlocked': url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=On' elif params['lock'] == False and state == 'Locked': url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Off' else: raise SmartHomeError(ERR_ALREADY_IN_STATE, 'Unable to execute {} for {}. Already in state '.format(command, self.state.entity_id)) else: if params['lock'] == True and state == 'Unlocked': url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Off' elif params['lock'] == False and state == 'Locked': url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=On' else: raise SmartHomeError(ERR_ALREADY_IN_STATE, 'Unable to execute {} for {}. Already in state '.format(command, self.state.entity_id)) if protected: url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass'] r = requests.get(url, auth=CREDITS) if protected: status = r.json() err = status.get('status') if err == 'ERROR': raise SmartHomeError(ERR_WRONG_PIN, 'Unable to execute {} for {} check your settings'.format(command, self.state.entity_id))
Example #10
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def execute(self, command, params): """Execute an ArmDisarm command.""" state = self.state.state seccode = self.state.seccode if params["arm"]: if params["armLevel"] == "Arm Home": if state == "Arm Home": raise SmartHomeError(ERR_ALREADY_IN_STATE, 'Unable to execute {} for {} '.format(command, self.state.entity_id)) else: self.state.state = "Arm Home" url = DOMOTICZ_URL + "/json.htm?type=command¶m=setsecstatus&secstatus=1&seccode=" + seccode if params["armLevel"] == "Arm Away": if state == "Arm Away": raise SmartHomeError(ERR_ALREADY_IN_STATE, 'Unable to execute {} for {} '.format(command, self.state.entity_id)) else: self.state.state = "Arm Away" url = DOMOTICZ_URL + "/json.htm?type=command¶m=setsecstatus&secstatus=2&seccode=" + seccode else: if state == "Normal": raise SmartHomeError(ERR_ALREADY_IN_STATE, 'Unable to execute {} for {} '.format(command, self.state.entity_id)) else: self.state.state = "Normal" url = DOMOTICZ_URL + "/json.htm?type=command¶m=setsecstatus&secstatus=0&seccode=" + seccode r = requests.get(url, auth=CREDITS)
Example #11
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def _execute_set_volume(self, params): level = params['volumeLevel'] url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str( int(level * self.state.maxdimlevel / 100)) r = requests.get(url, auth=CREDITS)
Example #12
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def _execute_volume_relative(self, params): # This could also support up/down commands using relativeSteps relative = params['volumeRelativeLevel'] current = level = self.state.level url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str( int(current + relative * self.state.maxdimlevel / 100)) r = requests.get(url, auth=CREDITS)
Example #13
Source File: trait.py From Domoticz-Google-Assistant with Apache License 2.0 | 5 votes |
def execute(self, command, params): """Execute a Timer command.""" if command == COMMAND_TIMER_START: logger.info('Make sure you have dzVents Dzga_Timer script installed and active') url = DOMOTICZ_URL + '/json.htm?type=command¶m=customevent&event=TIMER&data={"idx":' + self.state.id + ',"time":' + str(params['timerTimeSec']) + ',"on":true}' r = requests.get(url, auth=CREDITS) if command == COMMAND_TIMER_CANCEL: url = DOMOTICZ_URL + '/json.htm?type=command¶m=customevent&event=TIMER&data={"idx":' + self.state.id + ',"cancel":true}' r = requests.get(url, auth=CREDITS)
Example #14
Source File: actions.py From GassistPi with GNU General Public License v3.0 | 4 votes |
def domoticz_control(query,index,devicename): global hexcolour,bright,devorder try: for j in range(0,len(domoticz_devices['result'])): if domoticz_devices['result'][j]['idx']==index: devorder=j break if (' ' + custom_action_keyword['Dict']['On'] + ' ') in query or (' ' + custom_action_keyword['Dict']['On']) in query or (custom_action_keyword['Dict']['On'] + ' ') in query: devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=On",verify=False) say('Turning on ' + devicename ) if custom_action_keyword['Dict']['Off'] in query: devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=Off",verify=False) say('Turning off ' + devicename ) if 'toggle' in query: devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=Toggle",verify=False) say('Toggling ' + devicename ) if custom_action_keyword['Dict']['Colour'] in query: if 'RGB' in domoticz_devices['result'][devorder]['SubType']: rcolour,gcolour,bcolour,hexcolour,colour=getcolours(query) hexcolour=hexcolour.replace("#","",1) hexcolour=hexcolour.strip() print(hexcolour) if bright=='': bright=str(domoticz_devices['result'][devorder]['Level']) devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=setcolbrightnessvalue&idx=" + index + "&hex=" + hexcolour + "&brightness=" + bright + "&iswhite=false",verify=False) say('Setting ' + devicename + ' to ' + colour ) else: say('The requested light is not a colour bulb') if custom_action_keyword['Dict']['Brightness'] in query: if domoticz_devices['result'][devorder]['HaveDimmer']: if 'hundred' in query or 'hundred'.lower() in query or custom_action_keyword['Dict']['Maximum'] in query: bright=str(100) elif 'zero' in query or custom_action_keyword['Dict']['Minimum'] in query: bright=str(0) else: bright=re.findall('\d+', query) bright=bright[0] devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=Set%20Level&level=" + bright ,verify=False) say('Setting ' + devicename + ' brightness to ' + str(bright) + ' percent.') else: say('The requested light does not have a dimer') except (requests.exceptions.ConnectionError,TypeError) as errors: if str(errors)=="'NoneType' object is not iterable": print("Type Error") else: say("Device or Domoticz server is not online") #------------------------End of Domoticz Control Functions---------------------- #------------------------Start of Gaana Functions-------------------------------