Light automation - Dim-Levels

Sometimes I switch a shelly dimmer via webhooks from a shelly input. For this I use the toggle command in the URL. Now I want to go one step further and only switch between different dimming levels after sunset - between 80% and 20%. How could I realize this or is there a recommended best-practice way?