Can't the domoticz API be used to update this parameter in the hardware? I've developed a code to fetch the hardware info
Code: Select all
import requests
# Configuration
DOMOTICZ_URL = 'http://192.168.65.29:8080/json.htm'
# Function to fetch hardware information
def fetch_hardware_info():
response = requests.get(f"{DOMOTICZ_URL}?type=command¶m=gethardware")
if response.status_code == 200:
data = response.json()
return data['result']
else:
print("Error fetching hardware info:", response.status_code)
return None
# Function to filter and display Solax hardware information
def display_solax_info(hardware_info):
for hardware in hardware_info:
if hardware['Name'] == 'Solax':
print("Solax Hardware Information:")
print(f"ID: {hardware['idx']}")
print(f"Name: {hardware['Name']}")
print(f"Type: {hardware['Type']}")
print(f"Address: {hardware['Address']}")
print(f"Port: {hardware['Port']}")
print(f"Enabled: {hardware['Enabled']}")
print(f"Extra: {hardware['Extra']}")
print(f"LogLevel: {hardware['LogLevel']}")
print(f"DataTimeout: {hardware['DataTimeout']}")
print(f"SerialPort: {hardware['SerialPort']}")
print(f"Mode1: {hardware['Mode1']}")
print(f"Mode2: {hardware['Mode2']}")
print(f"Mode3: {hardware['Mode3']}")
print(f"Mode4: {hardware['Mode4']}")
print(f"Mode5: {hardware['Mode5']}")
print(f"Mode6: {hardware['Mode6']}")
break
else:
print("Solax hardware not found.")
# Main logic
hardware_info = fetch_hardware_info()
if hardware_info:
display_solax_info(hardware_info)
which outputs the following
Code: Select all
Solax Hardware Information:
ID: 18
Name: Solax
Type: 94
Address: 192.168.1.254
Port: 502
Enabled: true
Extra: SolaxMODBUS
LogLevel: 7
DataTimeout: 300
SerialPort:
Mode1: 30
Mode2: 1
Mode3:
Mode4:
Mode5:
Mode6: Normal
From where it is clear that Mode1 is the parameter which would have to be updated. I'm trying to do so with another python code
Code: Select all
import requests
# Configuration
DOMOTICZ_URL = 'http://192.168.65.29:8080/json.htm'
# Function to list parameters before updating Mode1
def list_parameters(hardware_id, new_mode1_value):
# Fetch the current hardware information to get the type and other parameters
response = requests.get(f"{DOMOTICZ_URL}?type=command¶m=gethardware")
if response.status_code == 200:
data = response.json()
hardware_info = data['result']
# Find the hardware by ID
for hardware in hardware_info:
if hardware['idx'] == hardware_id:
# Prepare the payload for updating Mode1
payload = {
'type': 'command',
'param': 'updatehardware',
'idx': hardware_id,
}
# Copy all parameters from the hardware dictionary
payload.update(hardware) # Copy all parameters directly
payload['Mode1'] = new_mode1_value
# Print the parameters to verify
print("Parameters to be sent:")
for key, value in payload.items():
print(f"{key}: {value}")
# print(payload)
# update hardware using payload
update_response = requests.get(DOMOTICZ_URL, params=payload)
if update_response.status_code == 200:
update_data = update_response.json()
if update_data['status'] == 'OK':
print(f"Successfully updated Mode1 to {new_mode1_value} for hardware ID {hardware_id}.")
else:
print("Error updating Mode1:", update_data)
else:
print("Error making request:", update_response.status_code)
break
else:
print("Hardware ID not found.")
else:
print("Error fetching hardware info:", response.status_code)
# Example usage
hardware_id = '18' # Replace with the actual ID of the Solax hardware
new_mode1_value = '11' # Replace with the desired new value for Mode1
list_parameters(hardware_id, new_mode1_value)
but I'm getting a Error updating Mode1: {'status': 'ERR'}
When the payload is printed everything seems to be fine though
Code: Select all
Parameters to be sent:
type: command
param: updatehardware
idx: 18
Address: 192.168.1.254
DataTimeout: 300
Enabled: true
Extra: SolaxMODBUS
LogLevel: 7
Mode1: 11
Mode2: 1
Mode3:
Mode4:
Mode5:
Mode6: Normal
Name: Solax
Password:
Port: 502
SerialPort:
Type: 94
Username: