Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Images don't seem to work #305

Open
mo-seph opened this issue Jan 14, 2025 · 3 comments
Open

[BUG] Images don't seem to work #305

mo-seph opened this issue Jan 14, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@mo-seph
Copy link

mo-seph commented Jan 14, 2025

I've got several entities working on a device (Buttons, Sensors etc.), and they all get picked up by Home Assistant:
image

I've added an Image to this, but it doesn't show up as a control, and it doesn't appear as an image entity that I can put into dashboards.

I can see the MQTT messages coming through:

topic:
homeassistant/image/Drawbot/Image/config
payload:
{
  "component": "image",
  "device": {
    "name": "Drawbot",
    "model": "fake",
    "identifiers": "drawbot"
  },
  "icon": "mdi:image",
  "name": "Image",
  "unique_id": "drawbot_image",
  "payload_available": "online",
  "payload_not_available": "offline",
  "state_topic": "hmd/image/Drawbot/Image/state",
  "json_attributes_topic": "hmd/image/Drawbot/Image/attributes",
  "command_topic": "hmd/image/Drawbot/Image/command"
}

and

topic:
hmd/image/Drawbot/Image/state
payload:
https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png

So it looks like MQTT is being sent, but HA isn't picking it up as an entity?

@unixorn
Copy link
Owner

unixorn commented Jan 15, 2025

Ok, that's weird. I haven't done anything with images myself, I'll try to look at it this weekend.

@unixorn unixorn added the bug Something isn't working label Jan 15, 2025
@mo-seph
Copy link
Author

mo-seph commented Jan 20, 2025

From the Image docs (https://www.home-assistant.io/integrations/image.mqtt/) it looks like url_topic or image_topic (for supplying bitstreams) would be the right field in an Image, rather than state_topic. I haven't quite understood the library structure well enough to poke at that myself.

@kratz00
Copy link
Contributor

kratz00 commented Feb 27, 2025

@mo-seph You are correct, here is some sample code which is using the state_topic as url_topic. Of course this is only a hack and I am working on a proper fix:

import asyncio
import logging

from ha_mqtt_discoverable import Settings, DeviceInfo
from ha_mqtt_discoverable.sensors import ImageInfo, Image
from paho.mqtt.client import Client, MQTTMessage

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


def my_callback(client: Client, user_data, message: MQTTMessage):
    pass


async def main():
    mqtt_settings = Settings.MQTT(host="192.168.0.216",
                                  username="someusername",
                                  password="somepassword")
    device_info = DeviceInfo(name="Drawbot", identifiers="unique_device_id")
    image_info = ImageInfo(name="Image",
                            device=device_info,
                            unique_id="unique_image_info_id",
                           url_topic="hmd/image/Drawbot/Image/state")
    settings = Settings(mqtt=mqtt_settings, entity=image_info)
    image = Image(settings, my_callback)
    image.set_url("https://octodex.github.com/images/baracktocat.jpg")

    while True:
        # update image here
        await asyncio.sleep(1)


if __name__ == '__main__':
    asyncio.run(main())

It is supposed to look like this then:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants