markgdev / home-assistant_OctopusAgile

Octopus Agile custom component for Home Assistant
Apache License 2.0
89 stars 32 forks source link

Sensors #56

Open lewiscf77 opened 3 years ago

lewiscf77 commented 3 years ago

Describe the bug Hi sorry if this is wrong place, I'm new to HA and am trying to get this working to charge the car.

I may have configured this incorrectly but I can't see how to configure the sensors.

In the readme it ends here. sensor:

platform: "octopusagile" To Reproduce My config.yaml.

run_devices:

energy_time: 2.5 entity_id: switch.office_heater run_before: '08:00:00' sensor: platform: "octopusagile"

Expected behavior Sensors show in HA

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

markgdev commented 3 years ago

Hi @lewiscf77, do you have any errors in the home assistant log file that might help narrow it down? Are you seeing any of the octopusagile entities? A formatted version of your config for the component would be useful too (Minus your account details)

lewiscf77 commented 3 years ago

Hi Mark,

Thanks for the reply. Sorry I think the sensors were complete user error. πŸ™

I think I have everything now setup correctly but for some reason I can't get it to trigger the switches. The timers are created but never triggered.

I love the integration guess i'm to daft to use it πŸ™‚πŸ‘Ž

Idea being the tesla charge switch is triggered to run for 5 hours at the lowest pricing.

Craig

octopusagile: region_code: "H" mpan: Secret serial: Secret auth: sk_live_Secret startdate: "2020-05-08" moneymakers:


From: Mark Gardner notifications@github.com Sent: 05 February 2021 19:33 To: markgdev/home-assistant_OctopusAgile home-assistant_OctopusAgile@noreply.github.com Cc: lewiscf77 Craig_F_Lewis@msn.com; Mention mention@noreply.github.com Subject: Re: [markgdev/home-assistant_OctopusAgile] Sensors (#56)

Hi @lewiscf77https://github.com/lewiscf77, do you have any errors in the home assistant log file that might help narrow it down? Are you seeing any of the octopusagile entities? A formatted version of your config for the component would be useful too (Minus your account details)

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/markgdev/home-assistant_OctopusAgile/issues/56#issuecomment-774243295, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASMJCVYI66EBCMPCBRDPCM3S5RBXRANCNFSM4XE2D7QQ.

markgdev commented 3 years ago

Hi @lewiscf77, Sounds like it’s nearly there. Your config looks good at a quick scan over. To confirm, you’re seeing octopusagile.timers get populated with your switch and times? If so, try calling the octopusagile.half_hour service from the developer tools. While you run it, have a look at the log and see if you see any errors. You can also edit the times on the timers entity in developer tools so that you don’t have to wait until one of your timers triggers to test. Let me know how you get on! Mark

GGW42 commented 3 years ago

Hi @lewiscf77 I was just wondering if you got this working? I did a 24hour test of my setup because I was fairly sure I saw an error in you configuration, as I had done a similar thing myself before and wanted to remind myself of what happened at that time.

I think your error is in the < run_devices: > section because it doesn't seem to work if you put an actual device entity in there, by way of example I have this device for my washing machine, under run_devices:

- energy_time: 0.5 entity_id: washing_machine run_before: '08:00:00' run_time: 0.5 The above YAML creates an entity called 'octopusagile.washing_machine' I then use an Automation to control the actual switch.

Replacing the entity_id: washing_machine with an actual switch (in my case 'switch.sinotimer_switch' that I use for testing) seems to stop both the timer & run device from working, nothing ever happens. Mark may know why, I have no clue but the logs do say this:-

Logger: custom_components.OctopusAgile Source: custom_components/OctopusAgile/__init__.py:355 Integration: OctopusAgile First occurred: 21 February 2021, 15:30:05 (53 occurrences) Last logged: 17:30:04 Invalid entity id encountered: octopusagile.switch.sinotimer_switch. Format should be <domain>.<object_id>

So perhaps I need to replace the second '.' with an '_' in the switch name? Not sure, but I haven't yet successfully got an actual switch to work there.

The timers section originally had the opposite problem in that the entity had to be a switch but mark changed that some months ago to allow 'input_boolean' instead of a switch and I use that for a second timer to trigger an Automation.

@markgdev FYI. The timers did get updated and looked like they should work but all failed last night, just as well the weather is warmer then last week :) `timers:

OK that's my view and I probably got a lot wrong but that's how it seems to work for me.

As a test just comment out that run device and I suspect your car will start charging.

Mark, feel free to point out any mistakes i have made, i am still learning HA and all the stuff that goes with it.

lewiscf77 commented 3 years ago

Hi,

Yes I think it was user error in the end.. Many thanks to Mark for pointing me in the right direction πŸ™‚

In the end I couldn't use the integration fully, as it kept switching off the device, when not in the time window. I was trying to use it to charge the car whilst at home using the car manufactures api. Which then stopped the car from charging away from home.

I need to invest in a different switching device that I can use this to control.

Craig


From: GGW42 notifications@github.com Sent: 22 February 2021 18:55 To: markgdev/home-assistant_OctopusAgile home-assistant_OctopusAgile@noreply.github.com Cc: lewiscf77 Craig_F_Lewis@msn.com; Mention mention@noreply.github.com Subject: Re: [markgdev/home-assistant_OctopusAgile] Sensors (#56)

Hi @lewiscf77https://github.com/lewiscf77 I was just wondering if you got this working? I did a 24hour test of my setup because I was fairly sure I saw an error in you configuration, as I had done a similar thing myself before and wanted to remind myself of what happened at that time.

I think your error is in the < run_devices: > section because it doesn't seem to work if you put an actual device entity in there, by way of example I have this device for my washing machine, under run_devices:

Replacing the entity_id: washing_machine with an actual switch (in my case 'switch.sinotimer_switch' that I use for testing) seems to stop both the timer & run device from working, nothing ever happens. Mark may know why, I have no clue but the logs do say this:-

Logger: custom_components.OctopusAgile Source: custom_components/OctopusAgile/init.py:355 Integration: OctopusAgile First occurred: 21 February 2021, 15:30:05 (53 occurrences) Last logged: 17:30:04 Invalid entity id encountered: octopusagile.switch.sinotimer_switch. Format should be .

So perhaps I need to replace the second '.' with an '_' in the switch name? Not sure, but I haven't yet successfully got an actual switch to work there.

The timers section originally had the opposite problem in that the entity had to be a switch but mark changed that some months ago to allow 'input_boolean' instead of a switch and I use that for a second timer to trigger an Automation.

@markgdevhttps://github.com/markgdev FYI. The timers did get updated and looked like they should work but all failed last night, just as well the weather is warmer then last week :) `timers:

OK that's my view and I probably got a lot wrong but that's how it seems to work for me.

As a test just comment out that run device and I suspect your car will start charging.

Mark, feel free to point out any mistakes i have made, i am still learning HA and all the stuff that goes with it.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/markgdev/home-assistant_OctopusAgile/issues/56#issuecomment-783595647, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASMJCV3BBFAYB4LTCZ3A6B3TAKSBNANCNFSM4XE2D7QQ.

GGW42 commented 3 years ago

Craig, you could just set a block time by changing the Block option to true, it will then allow find the cheapest block of hours (depending on your needs) and keep it switched on for that period each time. Shown in my example below is 2 x 3hour blocks.

block: true    #(Optional, note that if requirements are set, the block times will be taken from there.)
    requirements:
      - day_from: today
        day_to: tomorrow
        numHrs: 3
        time_from: '19:00:00'
        time_to: '09:00:00'
      - day_from: tomorrow
        day_to: tomorrow
        numHrs: 3
        time_from: '10:00:00'
        time_to: '16:00:00'

This works quite well.

lewiscf77 commented 3 years ago

Hi,

I now have this working pretty much as I want and it's awesome. Using the timers to call a hook switch that I use the state within node red to call a flow.

This probably the correct place for this (being a newby I apologise if it's not)! Is it possilbe to change how "money makers" work. I'd like to set a low value say <4p to switch on, not just when it's negative. I've tried to find how to do it myself but with no joy.

Craig


From: GGW42 notifications@github.com Sent: 23 February 2021 18:07 To: markgdev/home-assistant_OctopusAgile home-assistant_OctopusAgile@noreply.github.com Cc: lewiscf77 Craig_F_Lewis@msn.com; Mention mention@noreply.github.com Subject: Re: [markgdev/home-assistant_OctopusAgile] Sensors (#56)

Craig, you could just set a block time by changing the Block option to true, it will then allow find the cheapest block of hours (depending on your needs) and keep it switched on for that period each time. Shown in my example below is 2 x 3hour blocks.

block: true #(Optional, note that if requirements are set, the block times will be taken from there.) requirements:

This works quite well.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/markgdev/home-assistant_OctopusAgile/issues/56#issuecomment-784396231, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASMJCV3BTD6XLDY5PFGPDRDTAPVERANCNFSM4XE2D7QQ.

derekcfoley commented 3 years ago

Recently my HASS setup was updated, and your code no longer seems to work, I had to reinstall HACS and I reinstalled your code for Agile, yet I'm not able to get anything working. specifically the "current price".

image

I've gone back through and checked everything - obviously I put my account details into the configuration.yaml.

Is there something missing from the configuration - I'm wondering if there is something missing in the documentation and example config code - as it mentions:

"sensor Create a sensor for each of: current rate, previous rate and next rate"

Yet there isn't an example of this, only a sample configuration yaml with at the end a single entry of:

sensor:
- platform: "octopusagile"
markgdev commented 3 years ago

Yet there isn't an example of this, only a sample configuration yaml with at the end a single entry of: This is all that you need for the sensors.

I've updated HA today and tried to see if I could get the same issue but haven't been able to replicate. Did it sort itself out in the end? If you see it again, try running octopusagile.update_timers and then wait for the half hour to tick over and hopefully you'll be good to go. If not throw any errors you have in your log on here and I'll take a look.

markgdev commented 3 years ago

Hi, I now have this working pretty much as I want and it's awesome. Using the timers to call a hook switch that I use the state within node red to call a flow. This probably the correct place for this (being a newby I apologise if it's not)! Is it possilbe to change how "money makers" work. I'd like to set a low value say <4p to switch on, not just when it's negative. I've tried to find how to do it myself but with no joy. Craig

@lewiscf77 Sounds feasible to me, I'm not sure I'll get time anytime soon though but if you want to give it a go. I think a copy of the moneymakers section would work and change the 0 on this line to 4.

bobbinz commented 3 years ago

Recently my HASS setup was updated, and your code no longer seems to work, I had to reinstall HACS and I reinstalled your code for Agile, yet I'm not able to get anything working. specifically the "current price".

I just installed and get exactly the same thing, I can't get price info!

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 401, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 609, in async_device_update raise exc File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/octopusagile/sensor.py", line 159, in update current_rate = self.hass.states.get("octopusagile.all_rates").attributes.get(rounded_time_str) AttributeError: 'NoneType' object has no attribute 'attributes'

bobbinz commented 3 years ago

Oh no, I lied!

I just needed to be more patient and wait for the values to load after a half hour tick around!

Sorted!