pnbruckner / ha-sun2

Home Assistant Sun2 Sensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not sure if sun2 has integrated into my home assistant?

FFJacot opened this issue · comments

Hi,
I've installed the most recent version of sun2 using HACS and it appears as if the various components of the software are all in the right sort of places, and I can get a "Sun2" avatar onto my overview, but all it displays is "Update" and "up to date". This is not like the usual "sun" which can be set up to display various sensors.

I've entered a few of the sun2 sensors (some of the ones I want to use) into yaml files, but it's not clear to me they're actually available to applications.

Basically I have a switch I'd like to turn on and off at dusk and dawn. My automation using sun and sunset + offset and sunrise - offset worked fine, but I thought I could do better with sun2, so here I am confused. The editing of sensors into yaml files was interesting (first time doing this) but after some issues, managed to get them in OK, or to the extent I'm not getting errors.

Is there some simple "Hello world" type example that could, for example, display the values of the "daylight" or "night" sensor in a card of some sort?

I'm a 74 year old newbie home assistant, and willing to admit ignorance about a whole lot of things I should remember!

Thanks,
Jacot

Here's my automation using "sun":

- id: '1700317616358'
  alias: Switch 05 on 
  trigger:
  - platform: sun
    event: sunset
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    target:
      device_id: ddb6f420965b7964c52f8962b354365a
  mode: single

I changed "sun" to "sun2", and "sunset" to "dusk". but then get this error when running my automation:

Automation is unavailable
Triggers: Integration 'sun2' does not provide trigger support

Puzzled...?

When you said you installed the latest sun2 integration via HACS, do you mean version 2.5.1? Or do you mean the latest beta version? I'd suggest 2.5.1 for now.

What does you sun2 configuration look like? Can you share it here?

When properly configured, the sun2 integration creates entities in the sensor and/or binary_sensor domains. It does not create entities in the sun2 domain, and it does not support automation triggers directly.

For the use case you described, I'd recommend the following config:

binary_sensor:
  - platform: sun2
    monitored_conditions:
      - elevation: -6

That will create an entity whose ID is binary_sensor.elevation_above_minus_6. Its state will be on when the sun is above -6 degrees (i.e., after dawn), and off when the sun is below -6 degrees (i.e., after dusk.) You can then use it in automation triggers using state triggers like so:

trigger:
  # Trigger when sun rises above -6 degrees (at dawn)
  - platform: state
    entity_id: binary_sensor.elevation_above_minus_6
    to: "on"
  # Trigger when sun falls below -6 degrees (at dusk)
  - platform: state
    entity_id: binary_sensor.elevation_above_minus_6
    to: "off"

Thanks for response.... I suspect I'm misunderstanding something trivial!

I installed the beta version, but will revert to 2.5.1

here's my sensors.yaml

================================
# sensor file set up 2023/11/19
sensor:

  - platform: sun2
    monitored_conditions:
      - solar_midnight
      - astronomical_dawn
      - nautical_dawn
      - dawn
      - sunrise
      - solar_noon
      - sunset
      - dusk
      - nautical_dusk
      - astronomical_dusk
      - daylight
      - civil_daylight
      - nautical_daylight
      - astronomical_daylight
      - night
      - civil_night
      - nautical_night
      - astronomical_night
      - azimuth
      - elevation
      - min_elevation
      - max_elevation
      - sun_phase
      - deconz_daylight
      - time_at_elevation: 10
      - time_at_elevation: -10
        direction: setting
        icon: mdi:weather-sunset-down
        name: Setting past 10 deg below horizon
      - elevation_at_time: '12:00'
      - elevation_at_time: input_datetime.test
        name: Elv @ test time

  - platform: sun2
    entity_namespace: Grahamstown
    latitude: -33.3106721
    longitude: 26.522081
    elevation: 543
    timezone: Africa/Johannesburg
    monitored_conditions:
      - sunrise
      - sunset

binary_sensor:

=====================================

Your explanation of where/how the sensors are accessed is the missing link.

In the mean time, I've been trying to edit my automations file and making a real mess of the process - I have a long way to go getting familiar with the editing niceties. I'll try and implement an automation using your suggestion, but I'm missing something - you have:

trigger:
  # Trigger when sun rises above -6 degrees (at dawn)
  - platform: state
    entity_id: binary_sensor.elevation_above_minus_6
    to: "on"
  # Trigger when sun falls below -6 degrees (at dusk)
  - platform: state
    entity_id: binary_sensor.elevation_above_minus_6
    to: "off"

it's not clear how binary.sensor_elevation_above_minus_6 covers both those cases - surely one of them must be binary.sensor_elevation_below_minus_6?

I'll carry on refining my editing skillz and get back to you when I've managed to set up something.

I'm a 74 year old newbie home assistant, and willing to admit ignorance about a whole lot of things

I'm 64 years old, but I've been using HA for a few years. I can tell you it did have a steep learning curve, so don't feel bad.

I installed the beta version, but will revert to 2.5.1

That's best for now. I'm working on 3.0.0, which will hopefully be fully released before too long. It will allow you to do most config via the UI. But, since it's not yet stable (i.e., many beta releases), and you're just learning HA, it's better to use the stable 2.5.1 for now.

In your sensors.yaml, I can see you pretty much just copied and pasted from the doc. Do you really need all that? Also, this:

  - platform: sun2
    monitored_conditions:
  ...
  - platform: sun2
    entity_namespace: Grahamstown
    latitude: -33.3106721
    longitude: 26.522081
    elevation: 543
    timezone: Africa/Johannesburg
    monitored_conditions:
  ...

Do you real need sensors for two different locations? Or is the latter your location? If so, you don't need to specify it. Per the doc, latitude, longitude, elevation & timezone are optional. If you don't specify them (like in the first entry above) it will default to using those values from Home Assistant's "General" configuration.

it's not clear how binary.sensor_elevation_above_minus_6 covers both those cases - surely one of them must be binary.sensor_elevation_below_minus_6?

That one sensor changes its state to on when the sun rises above -6 degrees, which it does at dawn. And it changes its state to off when the sun falls below -6 degrees, which it does at dusk. That's why one trigger has to: "on" (for dawn) and the other has to: "off" (for dusk.) You can use both triggers in one automation if you want it to handle both events, or you can use one in one automation and the other in a second automation. That really depends on what you're trying to do.

BTW, I show the triggers in YAML, but you can create your automation(s) in the UI; just use state triggers.

Yup, my biggest Home assistant blunder was starting off installing it under docker which led to certain levels of depression when nothing was where it was supposed to be.. I abandoned it for a long time but started over about a week back, and things are much better - at least some things I spent days if not weeks trying to install have worked right away. I'm sure some of my current confusion is due to residual docker PTSD. Another irritation is that old eyes struggle sometimes with reading/seeing things clearly on screens.

And thanks for fixing my clumsy cut and paste of configs! How do you do that?

I've reverted to 2.5.1 (another trial and error learning exercise!), stripped down my sensors file, and removed the duplicate location. I copied everything because of uncertainty about what might break if left out,,,

I worked out eventually that the sensor had an on/off state, but am still struggling to put together an automation in the UI. Problem is that I have no real idea what a stripped down yaml version would look like, let alone how to link it to the switch device I want to use.

The learning curve is still steep, but at least I'm no longer thrashing around in the deep jungle - I'm getting to the local undergrowth.

And thanks for fixing my clumsy cut and paste of configs! How do you do that?

Click the Edit option in the "..." menu and see. 😉

How about this. Create the following binary sensor:

binary_sensor:
  - platform: sun2
    monitored_conditions:
      - elevation:
          above: -6
          name: Above Civil Dawn

This will create a binary sensor whose name is "Above Civil Dawn" and whose entity ID is binary_sensor.above_civil_dawn. (I think this name & entity ID are a bit clearer in the purpose of the sensor.)

Then create an automation trigger that looks like this:

image

If you click the three dot menu and check "Edit in YAML", you'll see the above is equivalent to:

image

Then, of course, add whatever actions you want to the automation.

@FFJacot do you still need help?

Ok. No problem. I'll close this for now. If you need more help, you can reopen it, open a new issue, or just ask the community for help on the HA forum.