def setup_platform(hass, config, add_entities, discovery_info=None): """Create the SolarEdge Monitoring API sensor.""" ip_address = config[CONF_IP_ADDRESS] platform_name = config[CONF_NAME] # Create new SolarEdge object to retrieve data api = SolarEdge("http://{}/".format(ip_address)) # Check if api can be reached and site is active try: status = api.get_status() status.energy # pylint: disable=pointless-statement _LOGGER.debug("Credentials correct and site is active") except AttributeError: _LOGGER.error("Missing details data in solaredge response") _LOGGER.debug("Response is: %s", status) return except (ConnectTimeout, HTTPError): _LOGGER.error("Could not retrieve details from SolarEdge API") return # Create solaredge data service which will retrieve and update the data. data = SolarEdgeData(hass, api) # Create a new sensor for each sensor type. entities = [] for sensor_key in SENSOR_TYPES: sensor = SolarEdgeSensor(platform_name, sensor_key, data) entities.append(sensor) add_entities(entities, True)
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Create the SolarEdge Monitoring API sensor.""" ip_address = config[CONF_IP_ADDRESS] platform_name = config[CONF_NAME] # Create new SolarEdge object to retrieve data. api = SolarEdge(f"http://{ip_address}/") # Check if api can be reached and site is active. try: status = api.get_status() _LOGGER.debug("Credentials correct and site is active") except AttributeError: _LOGGER.error("Missing details data in solaredge status") _LOGGER.debug("Status is: %s", status) return except (ConnectTimeout, HTTPError): _LOGGER.error("Could not retrieve details from SolarEdge API") return # Create solaredge data service which will retrieve and update the data. data = SolarEdgeData(hass, api) # Changing inverter temperature unit. inverter_temp_description = copy(SENSOR_TYPE_INVERTER_TEMPERATURE) if status.inverters.primary.temperature.units.farenheit: inverter_temp_description.native_unit_of_measurement = TEMP_FAHRENHEIT # Create entities entities = [ SolarEdgeSensor(platform_name, data, description) for description in (*SENSOR_TYPES, inverter_temp_description) ] try: if status.metersList[0]: entities.extend([ SolarEdgeSensor(platform_name, data, description) for description in SENSOR_TYPES_ENERGY_IMPORT ]) except IndexError: _LOGGER.debug("Import meter sensors are not created") try: if status.metersList[1]: entities.extend([ SolarEdgeSensor(platform_name, data, description) for description in SENSOR_TYPES_ENERGY_EXPORT ]) except IndexError: _LOGGER.debug("Export meter sensors are not created") add_entities(entities, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Create the SolarEdge Monitoring API sensor.""" ip_address = config[CONF_IP_ADDRESS] platform_name = config[CONF_NAME] # Create new SolarEdge object to retrieve data. api = SolarEdge(f"http://{ip_address}/") # Check if api can be reached and site is active. try: status = api.get_status() _LOGGER.debug("Credentials correct and site is active") except AttributeError: _LOGGER.error("Missing details data in solaredge status") _LOGGER.debug("Status is: %s", status) return except (ConnectTimeout, HTTPError): _LOGGER.error("Could not retrieve details from SolarEdge API") return # Changing inverter temperature unit. sensors = deepcopy(SENSOR_TYPES) if status.inverters.primary.temperature.units.farenheit: sensors["inverter_temperature"] = [ "invertertemperature", "Inverter Temperature", TEMP_FAHRENHEIT, "mdi:thermometer", ] # Create solaredge data service which will retrieve and update the data. data = SolarEdgeData(hass, api) # Create a new sensor for each sensor type. entities = [] for sensor_info in sensors.values(): sensor = SolarEdgeSensor( platform_name, data, sensor_info[0], sensor_info[1], sensor_info[2], sensor_info[3], ) entities.append(sensor) add_entities(entities, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Create the SolarEdge Monitoring API sensor.""" ip_address = config[CONF_IP_ADDRESS] platform_name = config[CONF_NAME] # Create new SolarEdge object to retrieve data. api = SolarEdge(f"http://{ip_address}/") # Check if api can be reached and site is active. try: status = api.get_status() _LOGGER.debug("Credentials correct and site is active") except AttributeError: _LOGGER.error("Missing details data in solaredge status") _LOGGER.debug("Status is: %s", status) return except (ConnectTimeout, HTTPError): _LOGGER.error("Could not retrieve details from SolarEdge API") return # Changing inverter temperature unit. sensors = deepcopy(SENSOR_TYPES) if status.inverters.primary.temperature.units.farenheit: sensors["inverter_temperature"] = [ "invertertemperature", "Inverter Temperature", TEMP_FAHRENHEIT, "mdi:thermometer", "operating_mode", DEVICE_CLASS_TEMPERATURE, ] try: if status.metersList[0]: sensors["import_current_power"] = [ "currentPowerimport", "current import Power", POWER_WATT, "mdi:arrow-collapse-down", None, None, ] sensors["import_meter_reading"] = [ "totalEnergyimport", "total import Energy", ENERGY_WATT_HOUR, "mdi:counter", None, None, ] except IndexError: _LOGGER.debug("Import meter sensors are not created") try: if status.metersList[1]: sensors["export_current_power"] = [ "currentPowerexport", "current export Power", POWER_WATT, "mdi:arrow-expand-up", None, None, ] sensors["export_meter_reading"] = [ "totalEnergyexport", "total export Energy", ENERGY_WATT_HOUR, "mdi:counter", None, None, ] except IndexError: _LOGGER.debug("Export meter sensors are not created") # Create solaredge data service which will retrieve and update the data. data = SolarEdgeData(hass, api) # Create a new sensor for each sensor type. entities = [] for sensor_info in sensors.values(): sensor = SolarEdgeSensor( platform_name, data, sensor_info[0], sensor_info[1], sensor_info[2], sensor_info[3], sensor_info[4], sensor_info[5], ) entities.append(sensor) add_entities(entities, True)
#!/usr/bin/env python3 # Original source: https://gitlab.com/snippets/1853864#L9 import datetime import os import time from solaredge_local import SolarEdge from google.protobuf.json_format import MessageToDict from influxdb import InfluxDBClient print("Inverter is located at: " + os.environ['INVERTER_HOST']) print("Writing to influx database \"" + os.environ['INFLUXDB_DATABASE'] + "\" at " + os.environ['INFLUXDB_HOST'] + ":" + os.environ['INFLUXDB_PORT']) se_client = SolarEdge("http://" + os.environ['INVERTER_HOST']) influx_client = InfluxDBClient(os.environ['INFLUXDB_HOST'], os.environ['INFLUXDB_PORT'], os.environ['INFLUXDB_USERNAME'], os.environ['INFLUXDB_PASSWORD'], os.environ['INFLUXDB_DATABASE']) def influx(fields): json_body = [{ "measurement": "solaredge", "time": datetime.datetime.utcnow().replace(microsecond=0).isoformat(), "fields": fields,
def connect_inverter(): try: return SolarEdge("http://{0}".format(inverter)) except TimeoutError: print("Can't connect to inverter - check network settings\n") sys.exit(1)