Closed kshepard339 closed 1 year ago
Thank you for building this out. I just updated to the latest version and tried to setup the feeder. I was getting connection error, so I reset the feeder and tried again. I am know getting the Sorry, there is no support for this device message. Here are the logs: Device matches None with quality of 0%. DPS: {"updated_at": 1686703712.5767665, "101": true, "103": false, "105": false, "106": "0", "108": "0", "109": "31243360|29811024|1432336", "110": 1, "117": 0, "134": false, "139": false, "150": false, "151": "2", "231": "", "235": 100, "238": 2, "239": "record_stop", "240": "no_voice", "241": "full", "242": "record_end", "244": true} Report this to https://github.com/make-all/tuya-local/issues/
I entered the id and key, and also selected 3.4 (but then tried all the other protocols). Not sure if it helps but just to test, I installed Local Tuya and tried the id and key and it connected with protocol 3.4 (it showed I could set these DPS: 101,103,105,106,108,109,110,117,134,139,151,231,235,238,239,240,241,242,244).
Please let me know if there is any other testing you want me to do. Thank you.
I updated my install with the file containing the optional updates. It did install! The switches were greyed out. I restarted home assistant and some switches looked to be on, if I turn them off in Home Assistant they turn right back on (and I don't see it reflect in the Tuya app). If I make a change in the app it is not reflected in HA.
When I was testing in local tuya just to confirm my connections (i completely removed local tuya before testing again in Tuya Local), I noticed that I was able to control/see the dps I listed in my last statement (regarding turning indicator on/off, ir on/off, see the sensors, etc); it looks like you can control the some functions of the device but the actual camera feed is only in Tuya app. Also, the other tuya did not give me the option for manual feed; I had to create a script to set the dps: alias: Manual Feed1 sequence:
I hope this info helps to narrow down the cause. Let me know if screen shots will help or if there is something else I can test. Thanks!
I started some more testing but need to do more later. Line 79 changing entity camera to switch lets me turn camera on/off and then allows flip switch to work.
The camera entity also has on/off services, you shouldn't need to cripple the implementation by changing it to a switch.
The aim should be to get the device supported the best it can be in Home Assistant, not to replicate what you hacked together within the limitations of localtuya.
Regarding the issues you are having, it isn't clear. Are there any log messages?
Hi, makes total sense to get the device supported the best it can be in Home Assistant and I like how you do this for all the devices. I put the code back so it is the camera entity again. I deleted the feeder and re-added it. I see these errors in the log:
Logger: homeassistant.components.camera Source: components/camera/init.py:461 Integration: Camera (documentation, issues) First occurred: 6:07:27 AM (2 occurrences) Last logged: 6:07:27 AM
Error adding entities for domain camera with platform tuya_local Error while setting up tuya_local platform for camera Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 673, in _async_write_ha_state if (entity_picture := self.entity_picture) is not None: ^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 461, in entity_picture return ENTITY_IMAGE_URL.format(self.entity_id, self.access_tokens[-1]) ^^^^^^^^^^^^^^^^^^ AttributeError: 'TuyaLocalCamera' object has no attribute 'access_tokens'
The other log message shows:
This error originated from a custom integration.
Logger: custom_components.tuya_local.device Source: components/camera/init.py:652 Integration: Tuya Local (documentation, issues) First occurred: 6:07:27 AM (1 occurrences) Last logged: 6:07:27 AM
Petlibro Camera Feeder receive loop terminated by exception 'TuyaLocalCamera' object has no attribute 'access_tokens' Traceback (most recent call last): File "/config/custom_components/tuya_local/device.py", line 218, in receive_loop entity.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 656, in _async_write_ha_state attr.update(self.state_attributes or {}) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 652, in state_attributes attrs = {"access_token": self.access_tokens[-1]} ^^^^^^^^^^^^^^^^^^ AttributeError: 'TuyaLocalCamera' object has no attribute 'access_tokens'
Strange, there is no mention of a requirement to support access_tokens here https://developers.home-assistant.io/docs/core/entity/camera
Very strange that the documentation doesn't mention access_tokens but it is causing an error.
Not related to the camera, but another issue I found is when selecting a number on manual feed, if I change it to 1 to dispense 1 serving this pops up at bottom of the screen: Failed to call service number/set_value.type NoneType doesn't defineroundmethod
This is in the log file: Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/tuya_local/helpers/device_config.py:610 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 6:15:39 AM (2 occurrences) Last logged: 6:17:35 AM
[139684807106768] type NoneType doesn't define round method Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1910, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1950, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 226, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 811, in entity_service_call future.result() # pop exception if have ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1034, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 851, in _handle_entity_call await result 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/tuya_local/number.py", line 104, in async_set_native_value await self._value_dps.async_set_value(self._device, value) File "/config/custom_components/tuya_local/helpers/device_config.py", line 445, in async_set_value settings = self.get_values_to_set(device, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/tuya_local/helpers/device_config.py", line 862, in get_values_to_set dps_map[self.id] = self._correct_type(result) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/tuya_local/helpers/device_config.py", line 610, in _correct_type result = int(round(result)) ^^^^^^^^^^^^^ TypeError: type NoneType doesn't define round method
I think I have fixed both the above problems. It turns out Camera has an init method that sets up some internal variables used internally. No other entity has this, so it was unexpected.
The second problem is because there is a mapping of null to 0 so that the number entity does not go unavailable when no value is being reported by the device. But due to nearest match code for numeric mappings, if that is the only mapping it matches to everything, which wasn't the intention. The null mapping shouldn't be applied in reverse even if the value is an exact match, as we never (I think) want to send null as a dp value.
Great job! I was able to confirm:
The only 2 things I didn't see on the interface are:
Sensors and diagnostic are reporting correctly (only thing I couldn't test was battery because device is always plugged in so batteries stay full. Batteries are just to feed on schedule set in the app as emergency backup - wifi turns off when on battery ).
If it loses power and comes back online the status states unknown but the first time it dispenses food it status correctly updates to feeding then standby; not a big deal since it gets the right status during next feeding.
Configuration components all working.
Again, great job. I am impressed with the layout and how everything is working!!
I am using the camera.py file that was updated a few hours ago. Here is the error I am seeing in the logs, maybe this will help point towards why the camera on/off and record on/off switch aren't visible in the configuration section.
This error originated from a custom integration.
Logger: aiohttp.server Source: custom_components/tuya_local/camera.py:71 Integration: Tuya Local (documentation, issues) First occurred: 6:12:48 PM (1 occurrences) Last logged: 6:12:48 PM
Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle result = await handler(request, **request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 734, in get if not camera.is_on: ^^^^^^^^^^^^ File "/config/custom_components/tuya_local/camera.py", line 71, in is_on return self._switch_dp.get_value(self.device) ^^^^^^^^^^^ AttributeError: 'TuyaLocalCamera' object has no attribute 'device'
Thanks for the log, I think this one is now fixed too.
Thanks. I do not see that error now, but Camera on/off and record on/off still not displaying in the interface.
I don't have any cameras, so I am not familiar with how they are expected to show in the UI. From screenshots, I don't see any of these controls, so I expect they are either in the more-info dialog, or only available by service calls.
If the camera responds to Call Service camera.turn_off, camera.turn_on, then the on/off is set up correctly. Looking at the docs though, the camera needs to support streaming before the record feature will work, so maybe that needs to be split out to a seperate switch.
This is my first Tuya device with a camera so not too sure about what would be shown. Unfortunately, I tried scanning the ports of the feeder but I can't get a stream; I think they aren't exposing it locally.
As a test, I added Camera (105) and Record (150) as switches to my petlibro yaml file (I left everything else as you had it) and that allowed me to toggle on/off each of them and I verified it was reflected in the Tuya app.
Once I tested that, I noticed in the Sensor section on the page 'Camera' is actual the Recording Status; turning camera on/off did not change the sensor but turning the new Record switch I put in had the sensor change between Recording and Idle.
Does it make sense to change the 'Camera' label in the Sensors section to Recorder and add Camera and Record in the config section as switches. I think that gives full control of everything needed.
I meant to add that I tested using Call Service camera.turn_off, camera.turn_on and it did work. I only tested adding it as a switch too because it wasn't showing in the config section as a toggle and it is good to see and access it there with all the other options.
If you need a switch in the UI, you can use an input helper, and call the turn off/on services from an automation triggered by the helper.
Yes, the camera can be done via an input helper but wouldn't record need to be split out to a separate switch since I do not see a service to call for the recorder in the HA developer tools screen.
Yes, record seems to not work as I expected (it expects HA to be doing the recording rather than the device itself) so will need to be split out.
Thanks for adding the record toggle. Here are my findings: In Controls section:
In Sensors section
In Configuration section:
All looks good, thanks for all the work on this!!
Thanks for all the effort on this - my PetLibro camera feeder now integrates and very impressed to see the camera feed working (when PetLibro support stressed to me this was fundamentally not accessible!)
Oddly though whilst I get access to the camera and motion settings in the entity page in HA, I do not see anything related to the feeding? i.e. no manual feed in configuration or amount etc. Is there a simple fix to this by chance?
EDIT: Ignore me, was being an idiot - I was attempting this with the standard Tuya integration that doesn't appear to expose any of the feeding functionality (albeit does expose the camera video feed)
I have now partially set up Local Tuya which exposes as per the above although also need to set up a script to execute the manual feeding function. I had to tweak your script as follows to get it to work by deleting the mode function which was I found was unsupported:
device_id: [insert device id from iot]
dp: 232
value: 1
Presumably, the only way to get the camera feed is by also using the Tuya integration?
Some Tuya cameras are standard WebRTC or ONVIF cameras that can be supported by other Home Assistant integrations if you can find the video stream address and password details. There is a tutorial here: https://shop.tuyaoem.com/add-tuya-security-camera-home-assistant-webrtc
I think the standard tuya integration is probably streaming via the tuya cloud.
Thanks - its the PLAF203 model and I can't find any settings page in the Tuya Smart app that mentions ONVIF - have a feeling this one doesn't expose an RTSP feed sadly but if anyone knows differently..
A small contribution in case it is not already obvious but if you want to show the dates of the last manual / scheduled feeds, you can use a template helper as follows:
Go to "Settings -> Devices and Services -> Helpers"
Select "+Add Helper"
Select "Template" helper
Use the following template pointing to the relevant Tuya attribute
`{% set x = states('sensor.last_manual_feed').split(',')[1] |replace('"time":', '') |replace('}', '') %}
{{ x | int | timestamp_custom("%d/%m/%Y %H:%M")}}`
This will then extract into a simple format (no TZ) and you can also extract the number of portions
My interface now looks like this - happy to share templates if of interest (double-clicking manual feed will provide a single portion)
I have plaf203_56 (I think 56 is the version of the software?). would this support plaf203 too?
I did manage to get PLAF203 working with HA but still have issues with Camera. I have latest version and followed the step by step guide in readme
Log Message
Information about DPS mappings
Product ID
product_id: "e1zs835joz1lc85q" product_name: "PLAF203 Camera Feeder" "model": "PLAF203"
Information about how the device functions
Product URL: https://petlibro.com/products/petlibro-granary-automatic-pet-feeder-with-camera?variant=40913462001711
Manual URL: https://cdn.shopify.com/s/files/1/0252/5197/1119/files/PETLIBRO_Granary_Camera_Monitoring_Feeder_PLAF203_USER_MANUAL.pdf?v=1682306122