Camera component: Cameras de transito Estradas.pt (decprecated)

Boas,
Estou com dificuldades em colocar esta info no meu Hassio.
Dá-me sempre erro na “Validação Configuração”.

Podem dar-me uma ajuda?
Obrigado desde já.

@NOG003 é importante saber qual o erro que dá e qual a configuração que tens…ninguém vai adivinhar se não partilhares o que tens.
É impossível alguém te ajudar assim.

1 Curtiu

Aparece estes erros.

2019-12-19 12:25:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:39 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.heater is taking over 10 seconds
2019-12-19 12:25:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:25:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:00 WARNING (MainThread) [homeassistant.components.switch] Updating broadlink switch took longer than the scheduled update interval 0:00:30
2019-12-19 12:26:08 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:08 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:09 ERROR (SyncWorker_0) [homeassistant.components.broadlink.switch] Timeout during authorization
2019-12-19 12:26:18 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:18 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:40 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.heater is taking over 10 seconds
2019-12-19 12:26:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:26:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:01 WARNING (MainThread) [homeassistant.components.switch] Updating broadlink switch took longer than the scheduled update interval 0:00:30
2019-12-19 12:27:10 ERROR (SyncWorker_16) [homeassistant.components.broadlink.switch] Timeout during authorization
2019-12-19 12:27:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:42 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.heater is taking over 10 seconds
2019-12-19 12:27:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:27:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:03 WARNING (MainThread) [homeassistant.components.switch] Updating broadlink switch took longer than the scheduled update interval 0:00:30
2019-12-19 12:28:08 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:08 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:12 ERROR (SyncWorker_6) [homeassistant.components.broadlink.switch] Timeout during authorization
2019-12-19 12:28:18 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:18 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:28 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:38 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:44 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.heater is taking over 10 seconds
2019-12-19 12:28:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:48 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2019-12-19 12:28:58 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.

@NOG003 acho que só leste metade do que escrevi, falta o resto sff.

@RodolfoVieira
tens razão. desculpa.

camera:
  - name: Ponte 25 Abril Norte
    platform: generic
    still_image_url: https://www.lusoponte.pt/assets/cam1_P25_00001.jpg
  - name: Ponte 25 Abril Sul
    platform: generic
    still_image_url: https://www.lusoponte.pt/assets/cam2_P25_00001.jpg
  - name: Ponte Vasco da Gama Norte
    platform: generic
    still_image_url: https://www.lusoponte.pt/assets/cam1_PVG_00001.jpg
  - name: Ponte Vasco da Gama Sul
    platform: generic
    still_image_url: https://www.lusoponte.pt/assets/cam2_PVG_00001.jpg

  - platform: estradas_pt
    name: testCam1
    input: "2ª Circular, km 3 - Radar Aeroporto"
    #extra_arguments: -q:v 2-32
  - platform: estradas_pt
    name: testCam2
    input: "IC20, km 1+000"
    #extra_arguments: -q:v 2-32

E tenho os ficheiros já colocados na pasta custom_components…

Mostra o conteudo da pasta estradas_pt

Ficheiro manifest.json

{
  "domain": "EstradasPT",
  "name": "Camaras Estradas PT",
  "documentation": "",
  "dependencies": ["ffmpeg"],
  "codeowners": ["@dpjrodrigues"],
  "requirements": ["pyEstradasPT==1.0.2"]
}

Ficheiro camera.py

"""
Support for Estradas.pt Cameras.
Based on https://home-assistant.io/components/camera.ffmpeg/
"""
import asyncio
import logging
import async_timeout
import voluptuous as vol

from datetime import datetime, timedelta
from homeassistant.util import Throttle
from homeassistant.const import CONF_NAME
from homeassistant.components.ffmpeg.camera import FFmpegCamera, PLATFORM_SCHEMA
from homeassistant.components.ffmpeg import (
    DATA_FFMPEG, CONF_INPUT, CONF_EXTRA_ARGUMENTS)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.aiohttp_client import (
    async_aiohttp_proxy_stream, async_get_clientsession)

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'estradas_pt'
IMAGE_REFRESH = 'image_refresh_in_min'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_INPUT): cv.string,
    vol.Optional(CONF_EXTRA_ARGUMENTS): cv.string,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Optional(IMAGE_REFRESH, default=5): cv.positive_int,
})

SCAN_INTERVAL = timedelta(minutes=1)


async def async_setup_platform(hass, config, async_add_entities,
                               discovery_info=None):
    """Set up a FFmpeg camera."""

    websession = async_get_clientsession(hass)

    from pyEstradasPT import Cameras
    #with async_timeout.timeout(10, loop=hass.loop):
    cams = await Cameras.get(websession) 
       
    url = await cams.UrlByCameraName(config.get(CONF_INPUT))      
    
    async_add_entities([EstradasCamera(hass, config, url.replace(".3gp?token=", ".webm?token="))])

class EstradasCamera(FFmpegCamera):
    """An implementation of an FFmpeg camera."""

    def __init__(self, hass, config, url):
        """Initialize a Estradas camera."""
        super().__init__(hass,config)

        self._manager = hass.data[DATA_FFMPEG]
        self._name = config.get(CONF_NAME)
        self._cam_name = config.get(CONF_INPUT)
        self._input = url
        self._token_changed = True
        self._extra_arguments = config.get(CONF_EXTRA_ARGUMENTS)
        self._last_update = datetime.now()
        self._last_image = None
        self._image_refresh = config.get(IMAGE_REFRESH)
        self._last_image_refresh = datetime.now()

    async def async_camera_image(self):
        """Return a still image response from the camera."""
        await self.async_update()
        
        d = (datetime.now()-self._last_image_refresh)
        ds = d.days * 86400 + d.seconds

        if (self._last_image == None or len(self._last_image) < 5 or ds >= self._image_refresh*60 ):
            self._last_image = await super().async_camera_image()
            self._last_image_refresh = datetime.now()

        return self._last_image

    async def handle_async_mjpeg_stream(self, request):
        """Generate an HTTP MJPEG stream from the camera."""
        await self.async_update()
        await super().handle_async_mjpeg_stream(request)

    @property
    def device_state_attributes(self):
        """Return other details about the sensor state."""
        attrs = {}
        attrs["camera_name"] = self._cam_name
        attrs["last_update"] = self._last_update
        attrs["token_changed"] = self._token_changed
        attrs["url"] = self._input
        attrs["image_refresh_in_min"] = self._image_refresh
        attrs["last_image_refresh"] = self._last_image_refresh
        return attrs 

    @Throttle(SCAN_INTERVAL)
    async def async_update(self):
        """Update the cam."""

        websession = async_get_clientsession(self.hass)
        
        from pyEstradasPT import Cameras
        #with async_timeout.timeout(10, loop=hass.loop):
        cams = await Cameras.get(websession) 
       
        url = await cams.UrlByCameraName(self._cam_name)
        url = url.replace(".3gp?token=", ".webm?token=")

        if url == self._input:
            self._token_changed = False
        else:
            self._token_changed = True
            self._input = url

        self._last_update = datetime.now()
        self.schedule_update_ha_state()

Ficheiro init.py

REQUIREMENTS = ['pyEstradasPT==1.0.2']
DEPENDENCIES = ['ffmpeg']

Obrigado pela ajuda

Boas
Começou a dar do nada… ainda bem!!

@NOG003 ok, vejo que o “problema” ficou resolvido… Mas sim, algumas vezes existe problemas do lado do estradas.pt ficando o componente impossibilitado de funcionar correctamente, mas aí nada a fazer.


Copyright © 2017-2021. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade