Skip to content

Commit

Permalink
Release 2023.12.1 Add day Sensor
Browse files Browse the repository at this point in the history
# Release 2023.12.1

## Added
- Day sensor

## Updated
- Boto3 1.28.58 -> 1.33.6
- Documentation

## Removed
- Nothing
  • Loading branch information
jobvk committed Dec 3, 2023
1 parent 4e52a1f commit 78eeb41
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ Go to Settings and then Devices & Service, select Integrations and search for th
### History

These sensors show how much power the wind turbine has delivered over a certain time.
These sensors are not displaying live data. These senors are updated around noon the following day.
These sensors are not displaying live data. These sensors are updated around noon the following day.

|ID|Type|Description|Unit of Measurement|
|----------|------------|------------|------------|
| `sensor.name_production_year_total` | Int | The energy produced by the wind turbine total this year. | Kilowatt-hour (kWh) |
| `sensor.name_production_month_total` | Int | The energy produced by the wind turbine total this month. | Kilowatt-hour (kWh) |
| `sensor.name_production_week_total` | Int | The energy produced by the wind turbine total this week. | Kilowatt-hour (kWh) |
| `sensor.name_production_day_total` | Int | The energy produced by the wind turbine total 1 or 2 days ago. | Kilowatt-hour (kWh) |
| `sensor.name_production_year_shares` | Int | The energy produced by your shares of the wind turbine this year. | Kilowatt-hour (kWh) |
| `sensor.name_production_month_shares` | Int | The energy produced by your shares of the wind turbine this month. | Kilowatt-hour (kWh) |
| `sensor.name_production_week_shares` | Int | The energy produced by your shares of the wind turbine this week. | Kilowatt-hour (kWh) |
| `sensor.name_production_day_shares` | Int | The energy produced by your shares of the wind turbine 1 or 2 days ago. | Kilowatt-hour (kWh) |

### News

Expand All @@ -93,7 +95,7 @@ The value of `sensor.the_windcentrale_news` doesn't change because the news stri

The attributes have no limit on characters there for I made a solution.

Create a markdown card with the following content:
Create a markdown card with the following content:
``` yaml
type: markdown
content: '{{ state_attr(''sensor.the_windcentrale_news'', ''News Item'') }}'
Expand All @@ -115,7 +117,7 @@ Below is an example of the sensors.

## Contributors
Special Thanks to all contributors
* [@vdheidenet](https://github.com/vdheidenet): Sharing his data for creating the signing in function
* [@vdheidenet](https://github.com/vdheidenet): for sharing his data on multiple windshares in different windturbines [#10](https://github.com/jobvk/Home-Assistant-Windcentrale/issues/10)

## Stargazers
Thanks to everyone having starred my repo!
Expand Down
4 changes: 3 additions & 1 deletion custom_components/windcentrale/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
"yeartotal": ["Production Year Total", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "YEAR3_YEARS"],
"monthtotal": ["Production Month Total", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "YEAR_MONTHS"],
"weektotal": ["Production Week Total", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "WEEK4_WEEKS"],
"daytotal": ["Production Day Total", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "MONTH_DAYS"],
"yearshares": ["Production Year Shares", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "YEAR3_YEARS"],
"monthshares": ["Production Month Shares", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "YEAR_MONTHS"],
"weekshares": ["Production Week Shares", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "WEEK4_WEEKS"]
"weekshares": ["Production Week Shares", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "WEEK4_WEEKS"],
"dayshares": ["Production Day Shares", ENERGY_KILO_WATT_HOUR, SensorDeviceClass.ENERGY, "MONTH_DAYS"]
}

class powerProducer:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/windcentrale/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/jobvk/Home-Assistant-Windcentrale/issues",
"loggers": ["boto3"],
"requirements": ["boto3==1.28.66", "pycognito==2023.5.0"],
"version": "2023.10.1"
}
"requirements": ["boto3==1.33.6", "pycognito==2023.5.0"],
"version": "2023.12.1"
}
75 changes: 63 additions & 12 deletions custom_components/windcentrale/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,21 @@ async def async_added_to_hass(self):
for i in range(3):
week = "Week " + str(datetime.now().isocalendar().week - i - 1)
self.attr[week] = state.attributes[week]
elif "Day " + str(datetime.now().day) in state.attributes:
for i in range(1, datetime.now().day + 1):
day = "Day {}".format(i)
self.attr[day] = state.attributes[day]

def update(self):
"""Update the sensor."""
self.attr.clear()
try:
if self.type == "yeartotal" :
self._state = self._windturbine.production_windtrubine_year_api.response_data[datetime.now().year]
for i in range(2):
self.attr["Year " + str(datetime.now().year - i - 1)] = self._windturbine.production_windtrubine_year_api.response_data[datetime.now().year - i - 1]
except KeyError as keyecx:
_LOGGER.warning('The year {} is missing in total production data'.format(keyecx))
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating total year production data. The error: {}'.format(exc))

Expand All @@ -131,8 +136,8 @@ def update(self):
for i in range(datetime.now().month - 1):
month = datetime.now() - dateutil.relativedelta.relativedelta(months= i+1)
self.attr[month.strftime("%B")] = self._windturbine.production_windtrubine_month_api.response_data[datetime.now().month - i - 1]
except KeyError as keyecx:
_LOGGER.warning('The month {} is missing in total production data'.format(keyecx))
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating total month production data. The error: {}'.format(exc))

Expand All @@ -141,18 +146,41 @@ def update(self):
self._state = self._windturbine.production_windtrubine_week_api.response_data[datetime.now().isocalendar().week]
for i in range(3):
self.attr["Week " + str(datetime.now().isocalendar().week - i - 1)] = self._windturbine.production_windtrubine_week_api.response_data[datetime.now().isocalendar().week - i - 1]
except KeyError as keyecx:
_LOGGER.warning('The week {} is missing in total production data'.format(keyecx))
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating total week production data. The error: {}'.format(exc))

try:
if self.type == "daytotal":
if datetime.now().day == 1:
self._state = 0
elif datetime.now().day > 1:
if self._windturbine.production_windtrubine_day_api.response_data[datetime.now().day - 1] == 0:
if datetime.now().day == 2:
self._state = self._windturbine.production_windtrubine_day_api.response_data[datetime.now().day - 1]
else:
self._state = self._windturbine.production_windtrubine_day_api.response_data[datetime.now().day - 2]
else:
self._state = self._windturbine.production_windtrubine_day_api.response_data[datetime.now().day - 1]
for i in range(1, datetime.now().day + 1):
day = "Day {}".format(i)
if i == datetime.now().day:
self.attr[day] = 0
else:
self.attr[day] = self._windturbine.production_windtrubine_day_api.response_data[i]
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating total day production data. The error: {}'.format(exc))

try:
if self.type == "yearshares" :
self._state = self._windturbine.production_shares_year_api.response_data[datetime.now().year]
for i in range(2):
self.attr["Year " + str(datetime.now().year - i - 1)] = self._windturbine.production_shares_year_api.response_data[datetime.now().year - i - 1]
except KeyError as keyecx:
_LOGGER.warning('The year {} is missing in shares production data'.format(keyecx))
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating shares year production data. The error: {}'.format(exc))

Expand All @@ -162,8 +190,8 @@ def update(self):
for i in range(datetime.now().month - 1):
month = datetime.now() - dateutil.relativedelta.relativedelta(months= i+1)
self.attr[month.strftime("%B")] = self._windturbine.production_shares_month_api.response_data[datetime.now().month - i - 1]
except KeyError as keyecx:
_LOGGER.warning('The month {} is missing in shares production data'.format(keyecx))
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating shares month production data. The error: {}'.format(exc))

Expand All @@ -172,11 +200,34 @@ def update(self):
self._state = self._windturbine.production_shares_week_api.response_data[datetime.now().isocalendar().week]
for i in range(3):
self.attr["Week " + str(datetime.now().isocalendar().week - i - 1)] = self._windturbine.production_shares_week_api.response_data[datetime.now().isocalendar().week - i - 1]
except KeyError as keyecx:
_LOGGER.warning('The week {} is missing in shares production data'.format(keyecx))
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating shares week production data. The error: {}'.format(exc))

try:
if self.type == "dayshares":
if datetime.now().day == 1:
self._state = 0
elif datetime.now().day > 1:
if self._windturbine.production_shares_day_api.response_data[datetime.now().day - 1] == 0:
if datetime.now().day == 2:
self._state = self._windturbine.production_shares_day_api.response_data[datetime.now().day - 1]
else:
self._state = self._windturbine.production_shares_day_api.response_data[datetime.now().day - 2]
else:
self._state = self._windturbine.production_shares_day_api.response_data[datetime.now().day - 1]
for i in range(1, datetime.now().day + 1):
day = "Day {}".format(i)
if i == datetime.now().day:
self.attr[day] = 0
else:
self.attr[day] = self._windturbine.production_shares_day_api.response_data[i]
except KeyError:
self._state = 0
except Exception as exc:
_LOGGER.error('There was an exception when updating shares day production data. The error: {}'.format(exc))

class NewsSensor(RestoreEntity, SensorEntity):
def __init__(self, wind):
"""Initialize the sensor."""
Expand Down
6 changes: 6 additions & 0 deletions custom_components/windcentrale/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ def __init__(self, wind, hass, windturbine_name, windturbine_code, windturbine_s
self.production_windtrubine_year_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "YEAR3_YEARS", 0, "TOTAL_PROJECT")
self.production_windtrubine_month_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "YEAR_MONTHS", 0, "TOTAL_PROJECT")
self.production_windtrubine_week_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "WEEK4_WEEKS", 0, "TOTAL_PROJECT")
self.production_windtrubine_day_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "MONTH_DAYS", 0, "TOTAL_PROJECT")
self.production_shares_year_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "YEAR3_YEARS", 0, "SHARES_IN_PROJECT")
self.production_shares_month_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "YEAR_MONTHS", 0, "SHARES_IN_PROJECT")
self.production_shares_week_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "WEEK4_WEEKS", 0, "SHARES_IN_PROJECT")
self.production_shares_day_api = ProductionAPI(self.hass, self.wind, self.id, self.name, "MONTH_DAYS", 0, "SHARES_IN_PROJECT")
self.production_update_task = None

async def schedule_update_production(self, interval):
Expand All @@ -145,9 +147,11 @@ async def async_update_production(self, *_):
await self.production_windtrubine_year_api.update()
await self.production_windtrubine_month_api.update()
await self.production_windtrubine_week_api.update()
await self.production_windtrubine_day_api.update()
await self.production_shares_year_api.update()
await self.production_shares_month_api.update()
await self.production_shares_week_api.update()
await self.production_shares_day_api.update()
await self.schedule_update_production(timedelta(hours=PRODUCTION_INTERVAL))

def cancel_scheduled_updates(self):
Expand Down Expand Up @@ -198,6 +202,8 @@ async def update(self):
date_object = json_item["labels"]["month"]
elif self.timeframe_type == "WEEK4_WEEKS":
date_object = json_item["labels"]["week"]
elif self.timeframe_type == "MONTH_DAYS":
date_object = json_item["labels"]["date"]["day"]

value = json_item["value"]

Expand Down
6 changes: 4 additions & 2 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ Below is an example of the sensors.
### History

These sensors show how much power the wind turbine has delivered over a certain time.
These sensors are not displaying live data. These senors are updated around noon the following day.
These sensors are not displaying live data. These sensors are updated around noon the following day.

|ID|Type|Description|Unit of Measurement|
|----------|------------|------------|------------|
| `sensor.name_production_year_total` | Int | The energy produced by the wind turbine total this year. | Kilowatt-hour (kWh) |
| `sensor.name_production_month_total` | Int | The energy produced by the wind turbine total this month. | Kilowatt-hour (kWh) |
| `sensor.name_production_week_total` | Int | The energy produced by the wind turbine total this week. | Kilowatt-hour (kWh) |
| `sensor.name_production_day_total` | Int | The energy produced by the wind turbine total 1 or 2 days ago. | Kilowatt-hour (kWh) |
| `sensor.name_production_year_shares` | Int | The energy produced by your shares of the wind turbine this year. | Kilowatt-hour (kWh) |
| `sensor.name_production_month_shares` | Int | The energy produced by your shares of the wind turbine this month. | Kilowatt-hour (kWh) |
| `sensor.name_production_week_shares` | Int | The energy produced by your shares of the wind turbine this week. | Kilowatt-hour (kWh) |
| `sensor.name_production_day_shares` | Int | The energy produced by your shares of the wind turbine 1 or 2 days ago. | Kilowatt-hour (kWh) |

### News

Expand Down Expand Up @@ -72,4 +74,4 @@ If you want to make donation as appreciation of my work, you can buy me a coffee

[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=flat&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/jobvk?frequency=one-time)
[![](https://img.shields.io/badge/PayPal-00457C?style=flat&logo=paypal&logoColor=white)](https://paypal.me/jobvankoeveringe)
[![Buy me a coffee](https://img.shields.io/badge/-buy_me_a%C2%A0coffee-gray?logo=buy-me-a-coffee&color=orange)](https://www.buymeacoffee.com/jobvk)
[![Buy me a coffee](https://img.shields.io/badge/-buy_me_a%C2%A0coffee-gray?logo=buy-me-a-coffee&color=orange)](https://www.buymeacoffee.com/jobvk)
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
boto3==1.28.66
pycognito==2023.5.0
boto3==1.33.6
pycognito==2023.5.0

0 comments on commit 78eeb41

Please sign in to comment.