Schnitzel / hass-miner

Controll your Bitcoin miner from Home Assistant
MIT License
56 stars 18 forks source link

Setting the power limit results in an error for S9 on Braiins+ #71

Closed cryptoteun closed 8 months ago

cryptoteun commented 2 years ago

Version of the custom_component

0.6.0

Configuration

I'm running HA in a docker setup. Installed the hass-miner plugin via HACS

Describe the bug

When I want to set the power limit (via an automation or the supplied power slider I run into the error below.

Debug log

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 111, in async_set_value
    await entity.async_set_native_value(native_value)
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 414, in async_set_native_value
    await self.hass.async_add_executor_job(self.set_native_value, value)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 410, in set_native_value
    raise NotImplementedError()
NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 688, in _async_device_step
    await device_action.async_call_action_from_config(
  File "/usr/src/homeassistant/homeassistant/components/device_automation/action.py", line 76, in async_call_action_from_config
    await platform.async_call_action_from_config(hass, config, variables, context)
  File "/usr/src/homeassistant/homeassistant/components/number/device_action.py", line 62, in async_call_action_from_config
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 113, in async_set_value
    await entity.async_set_value(value)
  File "/config/custom_components/miner/number.py", line 94, in async_set_value
    await miner.get_config()
  File "/usr/local/lib/python3.10/site-packages/miners/bosminer.py", line 99, in get_config
    cfg = bos_config_convert(toml_data)
  File "/usr/local/lib/python3.10/site-packages/config/bos.py", line 60, in bos_config_convert
    {} for _item in range(len(config[opt][idx]["pool"]))
KeyError: 'pool'
Schnitzel commented 2 years ago

mhh interesting, do you have a pool configured in your S9?

cryptoteun commented 2 years ago

Ah, you pointed me in the right direction. Apparently I had an empty pool created as well (next to the one I was using). When I removed the empty pool the component is working.

Thanks for the great work on this one. Cool to see that if you are thinking about some integration and you search for it, most likely someone has already created it :-D

Frenkel85 commented 1 year ago

I have a similar issue. My Home Assistant is losing connection when I flip the active switch from this integration, or when I adjust the power slider. It grays out and only gets back up after completely rebooting the Antminer physically. I have a pool configured. These are the errors I get in my Home Assistant log:

This error was caused by a custom integration.

Logger: root Source: custom_components/miner/coordinator.py:61 Integration: Miner (documentation, issues) First occurred: 10:43:23 (10 occurrences) Last logged: 10:44:03

192.168.178.119: API Command Error: temps: Not ready 192.168.178.119: API Command Error: Not ready

This error was caused by a custom integration.

Logger: custom_components.miner.coordinator Source: custom_components/miner/coordinator.py:61 Integration: Miner (documentation, issues) First occurred: 18 oktober 2022 21:18:01 (56881 occurrences) Last logged: 10:43:52

Unexpected error fetching Antminer S9i data: 'TimeoutError' object has no attribute 'winerror' Unexpected error fetching Antminer S9i data: 'OSError' object has no attribute 'winerror' Unexpected error fetching Antminer S9i data: 'FileNotFoundError' object has no attribute 'winerror' Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/API/init.py", line 106, in send_command reader, writer = await asyncio.open_connection(str(self.ip), self.port) File "/usr/local/lib/python3.10/asyncio/streams.py", line 47, in openconnection transport, = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') TimeoutError: [Errno 110] Connect call failed ('192.168.178.129', 4028)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh self.data = await self._async_update_data() File "/config/custom_components/miner/coordinator.py", line 61, in _async_update_data miner_api_data = await self.miner.api.multicommand( File "/usr/local/lib/python3.10/site-packages/API/init.py", line 81, in multicommand data = await self.send_command(command) File "/usr/local/lib/python3.10/site-packages/API/init.py", line 109, in send_command if e.winerror == "121": AttributeError: 'TimeoutError' object has no attribute 'winerror'

cryptoteun commented 1 year ago

I have the same when I change power setting, it's greying out. Connection to miner seems to be lost, but it's restarting BOS at that moment. When BOS is back the connection is restored automatically. But thats not your case?

Frenkel85 commented 1 year ago

Nope, unfortunately. I understand that when changing the power setting it needs to restart the BOS miner. The switch (on/off) also loses the connection and it won’t come back online anymore (in Home Assistant). Seems like something is not right, but I don’t know what it could be..

mcwago commented 1 year ago

same here: Home Assistant 2022.11.2 Frontend 20221108.0 - latest

HACS Integration version: | 1.28.3 Frontend version: | 20220906112053 miner component: v0.6.0

S9 with braiins: AntMiner S9 Miner Control Board Firmware Version | 2022-09-27-0-26ba61b9-22.08.1-plus System Version | LEDE Reboot 17.01.4 r3560-79f57e422d / LuCI bos+/stable-21.06 branch (git-21.099.47096-0790be2) Kernel Version | 4.4.0-xilinx-g3d0c3e6938c1-dirty

fresh docker install it seems link there are some api changes in new bosminer.

hey schnitzel, im able to give you an access to s9`s, ha and some coffee for fix it up :)) winter is comming 🥇

Blockvolt commented 1 year ago

Hi, i have the same problem! System-Data: Home Assistant Core 2022.12.8, Operating System 9.4 HACS 1.29.0 Hass-Miner 0.6.0 S9 Miner - Firmware Version 2022-09-27-0-26ba61b9-22.08.1-plus

When changing the powerlimit slider, BOSminer stops with error. I have to do a manual restart of the BOSminer. I think there is a problem with the communication of hass-miner and BOS Firmware after 27.09.2022. Did anyone tried a downgrade?

Log-Monitor: 2022-12-28T13:49:13.186153Z WARN bosminer_monitor::failsafe: activating failsafe mode 2022-12-28T13:49:13.207409Z INFO bosminer_monitor::led: changing miner status to Offline("BOSminer API error: Connection refused (os error 111)")

Log BOSMINER: 2022-12-28T13:49:12.945925Z WARN bosminer_plus_am1_s9: Parsing config failed with: unknown field psu_power_limit, expected one of enabled, mode, power_target, hashrate_target at line 22 column 1, using default config 2022-12-28T13:49:12.946871Z ERROR bosminer_plus_am1_s9: Error: missing model specification

Thanks Schnitzel for your reply!

Schnitzel commented 1 year ago

Hey all, sorry for the late reply... I was a bit busy with fiat job and getting my house heated with miners :)

Yes it seems that newer Braiins Software Versions have a change in their API and so it's currently failing to update settings on the S9 (or probably others as well). We have to update the code to support the new API version (but also the old one, so fun!)

I'll hopefully be able to work on this in the next couple of days, keep tuned. Currently the simplest is to downgrade to an older version, I know that for example 2022-06-20 of Braiins still works.

Frenkel85 commented 1 year ago

Any update on this? Would be great if it worked with the latest API again :)

Schnitzel commented 1 year ago

not yet, sorry, still trying to figure out what exactly has changed and how to fix this.

Blockvolt commented 1 year ago

not yet, sorry, still trying to figure out what exactly has changed and how to fix this.

This would be amazing :-)

Frenkel85 commented 1 year ago

@Schnitzel Thanks for the update!

Not sure if it's possible with the API commands available, but it would be really awesome if it would also be possible to set the fan-speed to a max (found at temperature & fans - fan control). This way you could set the fan speed (and power) lower when at home (having guests over) and you don't want the loud noise or the wobbly effect of the fans constant adjustments. And you can adjust the fans speed when people are not at home, making sure the heat will be blown into the house in a faster way. But I understand I'm asking much. It's already great that you created this add-on!

bostjannagode commented 1 year ago

not yet, sorry, still trying to figure out what exactly has changed and how to fix this.

Hello, maybe any progress on this issue for S9? Whenever any change is pushed toward Braiins, it hangs up... Onlyl manual restart from web interface brings it back...

samplex21 commented 1 year ago

@Schnitzel Hi, I really like your name :-D ... I have the same issue like @bostjannagode. If you could find a solution I would give some Sats via Lighning ;-) ... Support of S19 would be amazing. I would like to adjust the miner power according to my solar porduced power. Thanks sam

UpstreamData commented 1 year ago

Getting some movement going on this for you guys, we're working on pathing up PR #39 and these issues should be resolved.

bostjannagode commented 1 year ago

Any assistance needed?

klinge-wat commented 1 year ago

Hi,

I have the following problem:

System: HA: 10.5 Hass-Miner: v1.0.0-beta1 Raspberry 3 HACS: 1.32.1 S9 2022-04-29-0-5eb2c5fe-22.02.4-plus (Firmware: 22.02.4)

I can regulat the power limit between 0-100 % and not as shown in the video in watt (300 - 1420).

Also the actual value is shown as "NaN", when I slide it, I get the message: "number/set_value. required key not provided @ data['value']"

The S9 firmware takes the % as watt (PSU Power Limit), so my maximal power limit is than 100 watt.

best regards

Chris

Frenkel85 commented 1 year ago

Hi,

I have the following problem:

System: HA: 10.5 Hass-Miner: v1.0.0-beta1 Raspberry 3 HACS: 1.32.1 S9 2022-04-29-0-5eb2c5fe-22.02.4-plus

I can regulat the power limit between 0-100 % and not as shown in the video in watt (300 - 1420). The S9 firmware takes the % as watt (PSU Power Limit), so my maximal power limit is than 100 watt.

best regards

Chris

Same here indeed

Schnitzel commented 1 year ago

@klinge-wat @Frenkel85

Can you upgrade to the newest BraiinsOS Firmware? There have been some recent API changes. Plus make sure you run the beta version of Hass-Miner, see https://jumpshare.com/v/E1LD5km2XCKlBmga4pjD

klinge-wat commented 1 year ago

Hi Schnitzel,

I have tried it with the following system:

System: HA: 10.5 Hass-Miner: v1.0.0-beta1 Raspberry 3 HACS: 1.32.1 S9: 2022-09-27-0-26ba61b9-22.08.1-plus (Firmware: 22.08.1) / System is running from SD / Newest from Braiins homepage

Result: The miner will be found, but I have now the option to switch on/off the miner only. There is no option to set the power target. Also all other parameters are missing (hashrat, temperatur....), HA has found 1 entity only (on/off).
supplement->> Solved after a reboot of the miner, all entities found. The failure with the slider (0-100%) is still present.

I hope it will help.

Chris

Schnitzel commented 1 year ago

@klinge-wat can you check the homeassistant logs if you see an error there?

klinge-wat commented 1 year ago

I just checked HA and saw now 16 entities! Perfect! (maybe after a restart of my miner, I dont know)

Unfortunately, the same problem with the slider (0-100 % in HA and 0-100 in watt Braiins OS). -> There are no error logs.

Schnitzel commented 1 year ago

@UpstreamData have you ever heard of this 0-100% instead of actual wattage?

klinge-wat commented 1 year ago

image image

UpstreamData commented 1 year ago

@UpstreamData have you ever heard of this 0-100% instead of actual wattage?

That is strange. I wonder if it has to do with how home-assistant is handling the slider, is it possible the values are weird in the backend of HASS? pyasic appears to be setting the wattage in the expected way...

Schnitzel commented 1 year ago

the code sets the slider to 5000 max and 100 min:

https://github.com/Schnitzel/hass-miner/blob/d1fe269562668fc0018b4734deb01cfe790cb04f/custom_components/miner/number.py#L72-L74

so seems like something strange is going on here

klinge-wat commented 1 year ago

Today I saw an error log in HA:

2023-08-26 13:59:07.970 WARNING (MainThread) [homeassistant.components.number] custom_components.miner.number::MinerPowerLimitNumber is overriding deprecated methods on an instance of NumberEntity, this is not valid and will be unsupported from Home Assistant 2022.10. Please report it to the custom integration author.

UpstreamData commented 1 year ago

That's super helpful actually, I was looking through the code for custom components for the Number entity, and that's the exact error that I would have guessed would happen. I'll see if I can implement a fix.

Frenkel85 commented 1 year ago

Curious if there is any update on this? Did have the same issue, would be great if the slider scaling would work with the upcoming winter :)

Buster2k6 commented 12 months ago

I also cannot set a power limit; I receive the error message 'Error calling the service number/set_value. Required key not provided @ data['value'].' The rest is working great so far. I have installed Beta 1.0.0.-beta1 and am using it with an Antminer S9 Braiins+

klinge-wat commented 11 months ago

Any news for a fix?

Schnitzel commented 11 months ago

This should been addressed in v1.0.1. @klinge-wat and @Buster2k6 @Frenkel85 can you verify that upgrading solved this issue?

epper202 commented 11 months ago

Hi Michael, Firstly thank you and upstreamdata for the upgrade to V1.0.1 and the fixes it brought. Miners showing perfect data in HASS. However I also have the problem when I try to slide the slider from 2700 to 2000 let's say it doesn't work. "Failed to call service" The autotuning option is on and in braiins OS+ I can change it to any value so that does work. fault log hass github.odt Screenshot from 2023-11-15 20-11-43

no stress

UpstreamData commented 11 months ago

Do you happen to have the full log for this? I think I know what the issue is, it's trying to set the miner type in the configuration file, but for some reason your miner isn't being identified.

epper202 commented 11 months ago

Do you happen to have the full log for this? I think I know what the issue is, it's trying to set the miner type in the configuration file, but for some reason your miner isn't being identified.

Yes I do, can I send it to you private?

UpstreamData commented 11 months ago

Yeah it seems like that is the issue. I'll see if I can get a fix, I'm just not at home this week.

Feel free to DM me this stuff on telegram if you're worried about it, handle is b_rowan.

temurkhan88 commented 10 months ago

Hello having the same issue as aepper202. Is this a fix which will be applied in a future update or a setting that we can change?

`Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:230 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 8:36:34 PM (12 occurrences) Last logged: 9:34:11 PM

[281473093113920] Failed to set wattage. [281472969069248] Failed to set wattage. [281472960448960] Failed to set wattage. [281472933573952] Failed to set wattage. Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service return await service.entity_service_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call response_data = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/number/init.py", line 106, in async_set_value await entity.async_set_native_value(native_value) File "/config/custom_components/miner/number.py", line 123, in async_set_native_value raise pyasic.APIError("Failed to set wattage.") pyasic.errors.APIError: Failed to set wattage. `

klinge-wat commented 9 months ago

This should been addressed in v1.0.1. @klinge-wat and @Buster2k6 @Frenkel85 can you verify that upgrading solved this issue?

Hi Schnitzel,

sorry for my late reply, now I have some time during the days. And what should I say:

It works!

I can set up the wattage between 0 and 5000 W and the miner reacts correct. Can I limit the gap between 0 and 5000 W somewhere in HA, I think to have the possiblity to set 5000 W is not good for the miner (S9).

best regards & many thanks!

klinge

Frenkel85 commented 9 months ago

Yes! Works perfectly now. Great work!

UpstreamData commented 9 months ago

@klinge-wat I believe BraiinsOS itself will not allow you to set the wattage higher than the limit in the firmware. You can try it if you want and see, but maybe be ready to unplug your miner just in case.