{"id":13557,"date":"2023-07-03T10:55:52","date_gmt":"2023-07-03T10:55:52","guid":{"rendered":"https:\/\/www.rjt.org.uk\/home\/?post_type=home_assistant_tip&#038;p=13557"},"modified":"2023-07-03T10:57:52","modified_gmt":"2023-07-03T10:57:52","slug":"todays-sun-values","status":"publish","type":"home_assistant_tip","link":"https:\/\/www.rjt.org.uk\/home\/archives\/home-assistant-tip\/todays-sun-values\/","title":{"rendered":"Today&#8217;s sun values"},"content":{"rendered":"\n<p>Home assistant holds the next values for various sun events,  but it is nice to be able to use today&#8217;s value when reporting information.  Saving the values from the Sun sensor just after solar midnight will achieve this. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Template Sensor to collect today&#8217;s values just after midnight.<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># ------------------------------------------------------ Sun Data Sensor\n# When next midnight (solar) changes set values for Todays values\n\n- trigger:\n   - platform: state\n     entity_id: sensor.sun_next_midnight\n\n  sensor:\n  - name: Sun States Today\n    state: \"{{now().date()}}\"\n    attributes:\n      daylight_hours: >\n        {{ (state_attr('sun.sun','next_setting') | as_datetime) - (state_attr('sun.sun','next_rising') | as_datetime) }}\n      noon:    \"{{state_attr('sun.sun','next_noon') | as_datetime }}\"   \n      sunrise: \"{{state_attr('sun.sun','next_rising') | as_datetime }}\"\n      sunset:  \"{{state_attr('sun.sun','next_setting') | as_datetime }}\" \n      dawn: \"{{state_attr('sun.sun','next_dawn') | as_datetime }}\" \n      dusk: \"{{state_attr('sun.sun','next_dusk') | as_datetime }}\"  \n      midnight: \"{{state_attr('sun.sun','next_midnight') | as_datetime }}\" \n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Report the sunrise details<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The sun rose, 5 hours ago at 5:00 am and will set in 10 hours at 9:30 pm.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{%- macro sun_times() -%}\n{%- from \"easy_time.jinja\" import easy_time, big_time -%}\n{%- set sunrise  = state_attr('sensor.sun_states_today','sunrise') | as_datetime | as_local %}\n{%- set sunset  = state_attr('sensor.sun_states_today','sunset') | as_datetime | as_local %}\n{% set diff_rose = sunrise &lt; now() %}\n{%- set diff_set = sunset &lt; now() %}\n{{-('The sun will rise in %s ' | format(big_time(sunrise))) if not diff_rose}}\n{{- ('The sun rose %s ago ' | format(easy_time(sunrise))) if  diff_rose}}\n{{- 'at ' + sunrise.strftime('%_I:%M %p') + ' and '}} \n{{-('will set in %s' | format(easy_time(sunset))) if not  diff_set}}\n{{- ('set %s ago' | format(easy_time(sunset))) if  diff_set}}\n{{- ' at ' + sunset.strftime('%_I:%M %p')}}. \n{%- endmacro -%}\n\n{#-\nUsage\n-#}\n{%- from 'tools.jinja' import  sun_times -%}{{sun_times() -}}<\/pre>\n","protected":false},"template":"","class_list":["post-13557","home_assistant_tip","type-home_assistant_tip","status-publish","hentry","comments-off"],"_links":{"self":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip\/13557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip"}],"about":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/types\/home_assistant_tip"}],"wp:attachment":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/media?parent=13557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}