Code Monkey home page Code Monkey logo

Comments (21)

luci-11 avatar luci-11 commented on August 15, 2024 1

Hi,
I'm using nginx too. I use the addon by Frenck: Nginx Proxy Manager
I tested this 3 methods:
With local ip:

sensor:
  - platform: rest
    resource: "http://hassio_ip:8123/api/hassio/addons/xxxxxxxx_ringlivestream/info"
    headers:
      Authorization: "Bearer [Long_lived_token]"
      Content-Type: application/json
    name: ring_addon_official_online
    value_template: "{{value_json['data']['state']}}"

With domain:

sensor:
  - platform: rest
    resource: "https://yoursite.yourdomain.org/api/hassio/addons/xxxxxxxx_ringlivestream/info"
    headers:
      Authorization: "Bearer [Long_lived_token]"
      Content-Type: application/json
    name: ring_addon_official_online
    value_template: "{{value_json['data']['state']}}"

Or you can try the method below. It takes a couple of seconds to update after reboot and the sensor should be updated manually after start/stop command to the addon (so the switch is replaced by two scripts) :

sensor:
  - platform: command_line
    name: Supervisor_2
    command: 'curl https://yoursite.yourdomain.org/api/hassio/supervisor/info -H "Authorization: Bearer [Long_lived_token]" | jq ''{"state":.data.state,"slug":.data.slug,"addons":[.data.addons[] | select(.slug == "XXXXXXXX_ringlivestream")]}'''
    value_template: "{{ value_json.addons | length }}"
    json_attributes:
      - addons

  - platform: template
    sensors:
      ring_addon_status_from_command_line:
        friendly_name: "Ring"
        value_template: >-
          {{ state_attr('sensor.supervisor_2', 'addons')|regex_findall_index(".state'...(.+)', 'version'") }}

script:
  ring_start:
    sequence:
      - service: hassio.addon_start
        data:
          addon: XXXXXXXX_ringlivestream
      - service: shell_command.check_status
  ring_stop:
    sequence:
      - service: hassio.addon_stop
        data:
          addon: XXXXXXXX_ringlivestream
      - service: shell_command.check_status

shell_command:
  check_status: 'curl https://yoursite.yourdomain.org/api/hassio/supervisor/info -H "Authorization: Bearer [Long_Lived_Token]"'
 

This sensor is updated slower than the two above.

I'll do the PR for the .js part in some minutes.
I wanted also to tell you that in my case the stream works also without opening the port on router.

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

yep, I know that battery usage is an issue. I have not found a way to start/stop the stream when HA is looking at it or not. So maybe it would be better to run your Ring on wired power if you can? :)

from ring-hassio.

HarryJHolmes avatar HarryJHolmes commented on August 15, 2024

Yeah I have got it powered but obviously not sufficiently as it drained my doorbell 2 completely overnight. Is there no way to allow, for example, a 30 second stream and then wait for a new connection? @jeroenterheerdt

from ring-hassio.

HarryJHolmes avatar HarryJHolmes commented on August 15, 2024

@jeroenterheerdt The ring-homebrige integration doesn't drain battery so it must be possible?

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

the thing is that I have not found a way to activate the livestream on-demand.

from ring-hassio.

HarryJHolmes avatar HarryJHolmes commented on August 15, 2024

This looks useful
dgreif/ring#343 (comment)
@jeroenterheerdt

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

Yeah it does, problem is that I don't know how HA can tell us that we need a livestream. Something like the UI saying the ring card is in view or out of view would be useful

from ring-hassio.

HarryJHolmes avatar HarryJHolmes commented on August 15, 2024

I see what you mean. Surely when you open the stream on HA that’s when it uses the url to get a stream. I’m not sure it constantly streams all the time.

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

right, but how do we know HA does not need the stream any longer...? I am not seeing anything that I can use for example on the frontend to query if the stream is in view. To be fair, I have not looked into it that much.

from ring-hassio.

HarryJHolmes avatar HarryJHolmes commented on August 15, 2024

Would HA reconnect if you ended the stream every 30seconds or so until new connection?

from ring-hassio.

luci-11 avatar luci-11 commented on August 15, 2024

Hi guys, I don't know if it could be helpful but to save battery I did this (and it seems working)

  1. created a sensor based on addon status (started/stopped)
  2. created a switch to enable/disable the addon
  3. modified code in "livestream.js", case 5 is now like this:
                case 5:
                    sipSession = _a.sent();
                    sipSession.onCallEnded.subscribe(function () {
                        console.log('Call has ended');
                        server.close(function () { console.log('Server closed!'); });
                        // Destroy all open sockets
                        for (var socketId in sockets) {
                            console.log('socket', socketId, 'destroyed');
                            sockets[socketId].destroy();
                        }
                        app.stop();
			fs.unlinkSync(path);
                        //console.log('Restarting server');
                        //startStream();

Removing the old file when stopping addon makes that at next start the video is "updated", I also noticed that even if I stopped addon, I was still getting streams opening and closing with increasing numbers at this page: http://hassio.local:port/public/stream.m3u8
The problem I have is that we have a delay of around 10 secs.
Maybe this post can be helpful, maybe not :) (I don't know anything about js)
Anyway this addon is great! Thank a lot for your work @jeroenterheerdt !

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

Hmm, starting the addon on demand is an interesting idea. You could make a PR and add the things you did in HA to the readme please? Just make a section about configuration, we need to educate people not to use this addon for 24 hour streaming because the party will be over soon..

from ring-hassio.

luci-11 avatar luci-11 commented on August 15, 2024

PR opened for the Readme.
For the js part please give it a try as I don't know if all sockets and connections are closed properly (I don't know how to check)

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

@luci-11 - thanks - I am not entirely clear on what you changed, hence I asked for a PR so I can compare what you did.

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

I am not sure what is the difference between yours and mine config, but I cannot make this REST sensor work. I am using NGINX for extra security that I think is blocking this. The thought is interesting though, we should be able to make this work. Isn't there another way to get the status of an add-on?

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

I used the NGINX Home Assistant TSL Proxy, will check with the proxy manager to see if that changes anything. thanks.

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

well, that was quick - the Proxy Manager does not even start, no logging, nothing. Hmpf.

EDIT - nevermind - had to stop the other NGINX thing first. duh.

Ok that did not work. Back to the other add-on. Not sure what went wrong and I don't know enough of nginx to go configure my own proxy settings. Also, if we cannot make this work with the other add-on why bother in the first place?

And now the component does not work at all any more - no errors, but the livestream does not work, not with the port (3000) open in the router, not without... what the ....

@luci-11 I think we have a lot of issues with many different configurations being out there... multiple different options, ports, proxies, etc.

from ring-hassio.

angadsingh avatar angadsingh commented on August 15, 2024

@jeroenterheerdt great work man! please make this more stable and add on-demand starting/stopping of the RTSP server based on access. I created the template switch and sensor as suggested here and went ahead and created a script as well which will start the addon, cast the camera to my nest hub display, wait 1.5 minutes, stop the cast, and then finally stop the addon:

cast_ring_doorbell_to_nest_display:
  alias: Cast ring doorbell to nest display
  sequence:
  - data: {}
    entity_id: switch.ring_live_stream_addon_switch
    service: switch.turn_on
  - condition: state
    entity_id: switch.ring_live_stream_addon_switch
    state: 'on'
  - data:
      media_player: media_player.living_room_display
    entity_id: camera.ring_livestream
    service: camera.play_stream
  - delay: 00:01:30
  - data: {}
    entity_id: media_player.living_room_display
    service: media_player.media_stop
  - data: {}
    entity_id: switch.ring_live_stream_addon_switch
    service: switch.turn_off

however this was a big failure. it would take forever for the addon to achieve the on state, and then it would take forever for the cast to start streaming after initially showing up. if the addon itself killed its upstream link to the camera for battery preservation that would be much much faster. here's how the battery dies when using this addon:
B8AC1CC5-73CD-423D-9BF9-805617E98B31

notice the times when the addon was running its almost like a flat line. drains maybe 2% per day. with the addon running its almost 1% every 5 minutes. the only way to use this addon in its current state would be to have a wired power connection to the doorbell.

from ring-hassio.

angadsingh avatar angadsingh commented on August 15, 2024

@jeroenterheerdt you would not need a special callback or hook from HA to tell you that it is starting the stream. all it ultimately does is hit your stream URL, so maybe have either a nginx lua script or the rtsp server itself start the upstream fetch only when a hit comes to the url

from ring-hassio.

jeroenterheerdt avatar jeroenterheerdt commented on August 15, 2024

right, well, my node skills are next to none, so I really cannot make this work. feel free to take this code and take it further.

from ring-hassio.

bkr1969 avatar bkr1969 commented on August 15, 2024

resource: "https://yoursite.yourdomain.org/api/hassio/addons/xxxxxxxx_ringlivestream/info"

Where do you get this URL?
resource: "http://hassio_ip:8123/api/hassio/addons/xxxxxxxx_ringlivestream/info"

from ring-hassio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.